Changeset 89962 in vbox for trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp
- Timestamp:
- Jun 30, 2021 7:02:07 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 145421
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp
r89892 r89962 574 574 *********************************************************************************************************************************/ 575 575 576 int audioTestEnvConnectToHostAts(PAUDIOTESTENV pTstEnv, 577 const char *pszHostTcpAddr, uint32_t uHostTcpPort) 578 { 579 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connecting to host ATS at %s:%RU32 ...\n", 580 (pszHostTcpAddr && *pszHostTcpAddr) ? pszHostTcpAddr : ATS_TCP_HOST_DEFAULT_ADDR_STR, 581 uHostTcpPort ? uHostTcpPort : ATS_TCP_HOST_DEFAULT_PORT); 582 583 int rc = AudioTestSvcClientConnect(&pTstEnv->u.Host.AtsClValKit, pszHostTcpAddr, uHostTcpPort); 576 /** 577 * Connects an ATS client via TCP/IP to a peer. 578 * 579 * @returns VBox status code. 580 * @param pTstEnv Test environment to use. 581 * @param pClient Client to connect. 582 * @param pszWhat Hint of what to connect to where. 583 * @param pszTcpBindAddr TCP/IP bind address. Optionl and can be NULL. 584 * Server mode will be disabled then. 585 * @param uTcpBindPort TCP/IP bind port. Optionl and can be 0. 586 * Server mode will be disabled then. * 587 * @param pszTcpConnectAddr TCP/IP connect address. Optionl and can be NULL. 588 * Client mode will be disabled then. 589 * @param uTcpConnectPort TCP/IP connect port. Optionl and can be 0. 590 * Client mode will be disabled then. 591 */ 592 int audioTestEnvConnectViaTcp(PAUDIOTESTENV pTstEnv, PATSCLIENT pClient, const char *pszWhat, 593 const char *pszTcpBindAddr, uint16_t uTcpBindPort, 594 const char *pszTcpConnectAddr, uint16_t uTcpConnectPort) 595 { 596 RT_NOREF(pTstEnv); 597 598 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connecting %s ...\n", pszWhat); 599 600 RTGETOPTUNION Val; 601 RT_ZERO(Val); 602 603 int rc; 604 605 if ( !pszTcpBindAddr 606 || !uTcpBindPort) 607 { 608 Val.psz = "client"; 609 } 610 else if ( !pszTcpConnectAddr 611 || !uTcpConnectPort) 612 { 613 Val.psz = "server"; 614 } 615 else 616 Val.psz = "both"; 617 618 rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_MODE, &Val); 619 AssertRCReturn(rc, rc); 620 621 if ( !RTStrCmp(Val.psz, "client") 622 || !RTStrCmp(Val.psz, "both")) 623 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connecting at %s:%RU32\n", pszTcpConnectAddr, uTcpConnectPort); 624 625 if ( !RTStrCmp(Val.psz, "server") 626 || !RTStrCmp(Val.psz, "both")) 627 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Listening at %s:%RU32\n", pszTcpBindAddr ? pszTcpBindAddr : "<None>", uTcpBindPort); 628 629 if (pszTcpBindAddr) 630 { 631 Val.psz = pszTcpBindAddr; 632 rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_BIND_ADDRESS, &Val); 633 AssertRCReturn(rc, rc); 634 } 635 636 if (uTcpBindPort) 637 { 638 Val.u16 = uTcpBindPort; 639 rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_BIND_PORT, &Val); 640 AssertRCReturn(rc, rc); 641 } 642 643 if (pszTcpConnectAddr) 644 { 645 Val.psz = pszTcpConnectAddr; 646 rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_CONNECT_ADDRESS, &Val); 647 AssertRCReturn(rc, rc); 648 } 649 650 if (uTcpConnectPort) 651 { 652 Val.u16 = uTcpConnectPort; 653 rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_CONNECT_PORT, &Val); 654 AssertRCReturn(rc, rc); 655 } 656 657 rc = AudioTestSvcClientConnect(pClient); 584 658 if (RT_FAILURE(rc)) 585 659 { 586 RTTestFailed(g_hTest, "Connecting to host ATS failed with %Rrc\n", rc);660 RTTestFailed(g_hTest, "Connecting %s failed with %Rrc\n", pszWhat, rc); 587 661 return rc; 588 662 } 589 663 590 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connected to host ATS\n"); 591 return rc; 592 } 593 594 int audioTestEnvConnectToGuestAts(PAUDIOTESTENV pTstEnv, 595 const char *pszGuestTcpAddr, uint32_t uGuestTcpPort) 596 { 597 RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Connecting to guest ATS at %s:%RU32 ...\n", 598 (pszGuestTcpAddr && *pszGuestTcpAddr) ? pszGuestTcpAddr : "127.0.0.1", 599 uGuestTcpPort ? uGuestTcpPort : ATS_TCP_GUEST_DEFAULT_PORT); 600 601 int rc = AudioTestSvcClientConnect(&pTstEnv->u.Host.AtsClGuest, pszGuestTcpAddr, uGuestTcpPort); 664 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connected %s\n", pszWhat); 665 return rc; 666 } 667 668 /** 669 * Configures and starts an ATS TCP/IP server. 670 * 671 * @returns VBox status code. 672 * @param pSrv ATS server instance to configure and start. 673 * @param pCallbacks ATS callback table to use. 674 * @param pszDesc Hint of server type which is being started. 675 * @param pszTcpBindAddr TCP/IP bind address. Optionl and can be NULL. 676 * Server mode will be disabled then. 677 * @param uTcpBindPort TCP/IP bind port. Optionl and can be 0. 678 * Server mode will be disabled then. * 679 * @param pszTcpConnectAddr TCP/IP connect address. Optionl and can be NULL. 680 * Client mode will be disabled then. 681 * @param uTcpConnectPort TCP/IP connect port. Optionl and can be 0. 682 * Client mode will be disabled then. 683 */ 684 int audioTestEnvConfigureAndStartTcpServer(PATSSERVER pSrv, PCATSCALLBACKS pCallbacks, const char *pszDesc, 685 const char *pszTcpBindAddr, uint16_t uTcpBindPort, 686 const char *pszTcpConnectAddr, uint16_t uTcpConnectPort) 687 { 688 RTGETOPTUNION Val; 689 RT_ZERO(Val); 690 691 if (pszTcpBindAddr) 692 { 693 Val.psz = pszTcpBindAddr; 694 AudioTestSvcHandleOption(pSrv, ATSTCPOPT_BIND_ADDRESS, &Val); 695 } 696 697 if (uTcpBindPort) 698 { 699 Val.u16 = uTcpBindPort; 700 AudioTestSvcHandleOption(pSrv, ATSTCPOPT_BIND_PORT, &Val); 701 } 702 703 if (pszTcpConnectAddr) 704 { 705 Val.psz = pszTcpConnectAddr; 706 AudioTestSvcHandleOption(pSrv, ATSTCPOPT_CONNECT_ADDRESS, &Val); 707 } 708 709 if (uTcpConnectPort) 710 { 711 Val.u16 = uTcpConnectPort; 712 AudioTestSvcHandleOption(pSrv, ATSTCPOPT_CONNECT_PORT, &Val); 713 } 714 715 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Starting server for %s at %s:%RU32 ...\n", 716 pszDesc, pszTcpBindAddr[0] ? pszTcpBindAddr : "0.0.0.0", uTcpBindPort); 717 if (pszTcpConnectAddr[0]) 718 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Trying %s to connect as client to %s:%RU32 ...\n", 719 pszDesc, pszTcpConnectAddr[0] ? pszTcpConnectAddr : "0.0.0.0", uTcpConnectPort); 720 721 int rc = AudioTestSvcInit(pSrv, pCallbacks); 722 if (RT_SUCCESS(rc)) 723 rc = AudioTestSvcStart(pSrv); 724 602 725 if (RT_FAILURE(rc)) 603 { 604 RTTestFailed(g_hTest, "Connecting to guest ATS failed with %Rrc\n", rc); 605 return rc; 606 } 607 608 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connected to guest ATS\n"); 726 RTTestFailed(g_hTest, "Starting server for %s failed with %Rrc\n", pszDesc, rc); 727 609 728 return rc; 610 729 } … … 616 735 * @param pDrvReg Audio driver to use. 617 736 * @param fWithDrvAudio Whether to include DrvAudio in the stack or not. 618 * @param pszHostTcpAddr Host ATS TCP/IP address to connect to.619 * If NULL, ATS_TCP_HOST_DEFAULT_ADDR_STR will be used.620 * @param uHostTcpPort Host ATS TCP/IP port to connect to.621 * If 0, ATS_TCP_HOST_DEFAULT_PORT will be used.622 * @param pszGuestTcpAddr Guest ATS TCP/IP address to connect to.623 * If NULL, any address (0.0.0.0) will be used.624 * @param uGuestTcpPort Guest ATS TCP/IP port to connect to.625 * If 0, ATS_TCP_GUEST_DEFAULT_PORT will be used.626 737 */ 627 738 int audioTestEnvInit(PAUDIOTESTENV pTstEnv, 628 PCPDMDRVREG pDrvReg, bool fWithDrvAudio, 629 const char *pszHostTcpAddr, uint32_t uHostTcpPort, 630 const char *pszGuestTcpAddr, uint32_t uGuestTcpPort) 739 PCPDMDRVREG pDrvReg, bool fWithDrvAudio) 631 740 { 632 741 int rc = VINF_SUCCESS; … … 656 765 if (!pDrvReg) 657 766 pDrvReg = AudioTestGetDefaultBackend(); 658 659 if (!uHostTcpPort)660 uHostTcpPort = ATS_TCP_HOST_DEFAULT_PORT;661 662 if (!uGuestTcpPort)663 uGuestTcpPort = ATS_TCP_GUEST_DEFAULT_PORT;664 767 665 768 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Initializing environment for mode '%s'\n", pTstEnv->enmMode == AUDIOTESTMODE_HOST ? "host" : "guest"); … … 732 835 return rc; 733 836 734 /** @todo Implement NAT mode like we do for TxS later? */735 837 if (pTstEnv->enmMode == AUDIOTESTMODE_GUEST) 736 838 { … … 749 851 Callbacks.pvUser = &Ctx; 750 852 853 if (!pTstEnv->u.Guest.TcpOpts.uTcpBindPort) 854 pTstEnv->u.Guest.TcpOpts.uTcpBindPort = ATS_TCP_DEF_BIND_PORT_GUEST; 855 856 if (!pTstEnv->u.Guest.TcpOpts.szTcpBindAddr[0]) 857 RTStrCopy(pTstEnv->u.Guest.TcpOpts.szTcpBindAddr, sizeof(pTstEnv->u.Guest.TcpOpts.szTcpBindAddr), "0.0.0.0"); 858 859 if (!pTstEnv->u.Guest.TcpOpts.uTcpConnectPort) 860 pTstEnv->u.Guest.TcpOpts.uTcpConnectPort = ATS_TCP_DEF_CONNECT_PORT_GUEST; 861 862 if (!pTstEnv->u.Guest.TcpOpts.szTcpConnectAddr[0]) 863 RTStrCopy(pTstEnv->u.Guest.TcpOpts.szTcpConnectAddr, sizeof(pTstEnv->u.Guest.TcpOpts.szTcpConnectAddr), "10.0.2.2"); 864 751 865 /* 752 866 * Start the ATS (Audio Test Service) on the guest side. … … 756 870 * Note that we have to bind to "0.0.0.0" by default so that the host can connect to it. 757 871 */ 758 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Starting guest ATS at %s:%RU32...\n", 759 (pszGuestTcpAddr && *pszGuestTcpAddr) ? pszGuestTcpAddr : "0.0.0.0", uGuestTcpPort); 760 rc = AudioTestSvcInit(&pTstEnv->u.Guest.Srv, 761 (pszGuestTcpAddr && *pszGuestTcpAddr) ? pszGuestTcpAddr : "0.0.0.0", uGuestTcpPort, &Callbacks); 872 rc = audioTestEnvConfigureAndStartTcpServer(&pTstEnv->u.Guest.Srv, &Callbacks, "Guest ATS", 873 pTstEnv->u.Guest.TcpOpts.szTcpBindAddr, pTstEnv->u.Guest.TcpOpts.uTcpBindPort, 874 pTstEnv->u.Guest.TcpOpts.szTcpConnectAddr, pTstEnv->u.Guest.TcpOpts.uTcpConnectPort); 875 876 } 877 else /* Host mode */ 878 { 879 880 ATSCALLBACKCTX Ctx; 881 Ctx.pTstEnv = pTstEnv; 882 883 ATSCALLBACKS Callbacks; 884 RT_ZERO(Callbacks); 885 Callbacks.pvUser = &Ctx; 886 887 if (!pTstEnv->u.Host.TcpOpts.uTcpBindPort) 888 pTstEnv->u.Host.TcpOpts.uTcpBindPort = ATS_TCP_DEF_BIND_PORT_HOST; 889 890 if (!pTstEnv->u.Host.TcpOpts.szTcpBindAddr[0]) 891 RTStrCopy(pTstEnv->u.Host.TcpOpts.szTcpBindAddr, sizeof(pTstEnv->u.Host.TcpOpts.szTcpBindAddr), "0.0.0.0"); 892 893 if (!pTstEnv->u.Host.TcpOpts.uTcpConnectPort) 894 pTstEnv->u.Host.TcpOpts.uTcpConnectPort = ATS_TCP_DEF_CONNECT_PORT_HOST_PORT_FWD; 895 896 if (!pTstEnv->u.Host.TcpOpts.szTcpConnectAddr[0]) 897 RTStrCopy(pTstEnv->u.Host.TcpOpts.szTcpConnectAddr, sizeof(pTstEnv->u.Host.TcpOpts.szTcpConnectAddr), 898 ATS_TCP_DEF_CONNECT_HOST_ADDR_STR); /** @todo Get VM IP? Needs port forwarding. */ 899 900 /* We need to start a server on the host so that VMs configured with NAT networking 901 * can connect to it as well. */ 902 rc = AudioTestSvcClientCreate(&pTstEnv->u.Host.AtsClGuest); 762 903 if (RT_SUCCESS(rc)) 763 rc = AudioTestSvcStart(&pTstEnv->u.Guest.Srv); 764 765 if (RT_FAILURE(rc)) 766 RTTestFailed(g_hTest, "Starting ATS failed with %Rrc\n", rc); 767 } 768 else /* Host mode */ 769 { 770 rc = audioTestEnvConnectToHostAts(pTstEnv, pszHostTcpAddr, uHostTcpPort); 904 rc = audioTestEnvConnectViaTcp(pTstEnv, &pTstEnv->u.Host.AtsClGuest, 905 "Host -> Guest ATS", 906 pTstEnv->u.Host.TcpOpts.szTcpBindAddr, pTstEnv->u.Host.TcpOpts.uTcpBindPort, 907 pTstEnv->u.Host.TcpOpts.szTcpConnectAddr, pTstEnv->u.Host.TcpOpts.uTcpConnectPort); 771 908 if (RT_SUCCESS(rc)) 772 rc = audioTestEnvConnectToGuestAts(pTstEnv, pszGuestTcpAddr, uGuestTcpPort); 909 { 910 if (!pTstEnv->ValKitTcpOpts.uTcpConnectPort) 911 pTstEnv->ValKitTcpOpts.uTcpConnectPort = ATS_TCP_DEF_CONNECT_PORT_VALKIT; 912 913 if (!pTstEnv->ValKitTcpOpts.szTcpConnectAddr[0]) 914 RTStrCopy(pTstEnv->ValKitTcpOpts.szTcpConnectAddr, sizeof(pTstEnv->ValKitTcpOpts.szTcpConnectAddr), 915 ATS_TCP_DEF_CONNECT_HOST_ADDR_STR); 916 917 rc = AudioTestSvcClientCreate(&pTstEnv->u.Host.AtsClValKit); 918 if (RT_SUCCESS(rc)) 919 rc = audioTestEnvConnectViaTcp(pTstEnv, &pTstEnv->u.Host.AtsClValKit, 920 "Host -> Validation Kit Host Audio Driver ATS", 921 pTstEnv->ValKitTcpOpts.szTcpBindAddr, pTstEnv->ValKitTcpOpts.uTcpBindPort, 922 pTstEnv->ValKitTcpOpts.szTcpConnectAddr, pTstEnv->ValKitTcpOpts.uTcpConnectPort); 923 } 773 924 } 774 925
Note:
See TracChangeset
for help on using the changeset viewer.