ProcessLaunchMain.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <iostream>
  9. #include <AzCore/std/utility/charconv.h>
  10. #include <AzFramework/CommandLine/CommandLine.h>
  11. // this is an intentional relative local include so that it can be shared between two unrelated projects
  12. // namely this one shot test executable, and the tests which run it in a different project with no relation.
  13. #include "ProcessLaunchTestTokens.h"
  14. void OutputArgs(const AzFramework::CommandLine& commandLine)
  15. {
  16. std::cout << "Switch List:" << std::endl;
  17. for (auto& switchPair : commandLine)
  18. {
  19. // We strip white space from all of our switch names, so "flush" names will start arguments
  20. if (!switchPair.m_option.empty())
  21. {
  22. std::cout << switchPair.m_option.c_str() << std::endl;
  23. }
  24. std::cout << " " << switchPair.m_value.c_str() << std::endl;
  25. }
  26. std::cout << "End Switch List:" << std::endl;
  27. }
  28. int main(int argc, char** argv)
  29. {
  30. using namespace ProcessLaunchTestInternal;
  31. const AZ::Debug::Trace tracer;
  32. int exitCode = 0;
  33. {
  34. AzFramework::CommandLine commandLine;
  35. commandLine.Parse(argc, argv);
  36. if (commandLine.GetNumSwitchValues("exitCode") > 0)
  37. {
  38. exitCode = atoi(commandLine.GetSwitchValue("exitCode").c_str());
  39. const AZStd::string& exitCodeStr = commandLine.GetSwitchValue("exitCode");
  40. AZStd::from_chars(exitCodeStr.begin(), exitCodeStr.end(), exitCode);
  41. }
  42. if (commandLine.HasSwitch("plentyOfOutput"))
  43. {
  44. // special case - plenty of output mode requires that it output an easily recognizable begin
  45. // then plentiful output (enough to saturate any buffers) then output a recognizable end.
  46. // this makes sure that if there are any buffers that get filled up or overwritten we can detect
  47. // deadlock or buffer starvation or buffer overflows.
  48. size_t midLength = strlen(s_midToken);
  49. size_t beginLength = strlen(s_beginToken);
  50. size_t endLength = strlen(s_endToken);
  51. auto spamABunchOfLines = [&](FILE *fileDescriptor)
  52. {
  53. fwrite(s_beginToken, beginLength, 1, fileDescriptor);
  54. size_t currentBytesOutput = beginLength;
  55. while (currentBytesOutput < s_numOutputBytesInPlentyMode - endLength)
  56. {
  57. fwrite(s_midToken, midLength, 1, fileDescriptor);
  58. currentBytesOutput += midLength;
  59. }
  60. fwrite(s_endToken, endLength, 1, fileDescriptor);
  61. };
  62. spamABunchOfLines(stdout);
  63. if (exitCode != 0)
  64. {
  65. // note that stderr is unbuffered so this will take longer!
  66. spamABunchOfLines(stderr);
  67. }
  68. }
  69. else
  70. {
  71. OutputArgs(commandLine);
  72. }
  73. }
  74. return exitCode;
  75. }