Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 1 | //===-- main.cpp ------------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include <cstdlib> |
| 11 | #include <string> |
| 12 | #include <fstream> |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 13 | #include <iostream> |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 14 | |
Daniel Malea | d79ae05 | 2013-08-07 21:54:09 +0000 | [diff] [blame^] | 15 | int numberfn() |
| 16 | { |
| 17 | return 0x5a; |
| 18 | } |
| 19 | |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 20 | int |
| 21 | main(int argc, char const *argv[]) |
| 22 | { |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 23 | // The program writes its output to the following file: |
| 24 | // |
| 25 | // o "output1.txt" for test_pass_host_env_vars() test case |
| 26 | // o "output2.txt" for test_run_args_and_env_vars_with_dsym() test case |
| 27 | // o "output2.txt" for test_run_args_and_env_vars_with_dwarf() test case |
| 28 | std::ofstream outfile; |
| 29 | if (argc == 1) |
| 30 | outfile.open("output1.txt"); |
| 31 | else |
| 32 | outfile.open("output2.txt"); |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 33 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 34 | for (unsigned i = 0; i < argc; ++i) { |
| 35 | std::string theArg(argv[i]); |
| 36 | if (i == 1 && "A" == theArg) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 37 | outfile << "argv[1] matches\n"; |
| 38 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 39 | if (i == 2 && "B" == theArg) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 40 | outfile << "argv[2] matches\n"; |
| 41 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 42 | if (i == 3 && "C" == theArg) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 43 | outfile << "argv[3] matches\n"; |
| 44 | } |
| 45 | |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 46 | // For passing environment vars from the debugger to the launched process. |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 47 | if (::getenv("MY_ENV_VAR")) { |
| 48 | std::string MY_ENV_VAR(getenv("MY_ENV_VAR")); |
| 49 | if ("YES" == MY_ENV_VAR) { |
| 50 | outfile << "Environment variable 'MY_ENV_VAR' successfully passed.\n"; |
| 51 | } |
| 52 | } |
| 53 | |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 54 | |
| 55 | // For passing host environment vars to the launched process. |
| 56 | if (::getenv("MY_HOST_ENV_VAR1")) { |
| 57 | std::string MY_HOST_ENV_VAR1(getenv("MY_HOST_ENV_VAR1")); |
| 58 | if ("VAR1" == MY_HOST_ENV_VAR1) { |
| 59 | outfile << "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.\n"; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | if (::getenv("MY_HOST_ENV_VAR2")) { |
| 64 | std::string MY_HOST_ENV_VAR2(getenv("MY_HOST_ENV_VAR2")); |
| 65 | if ("VAR2" == MY_HOST_ENV_VAR2) { |
| 66 | outfile << "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed.\n"; |
| 67 | } |
| 68 | } |
| 69 | |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 70 | std::cerr << "This message should go to standard error.\n"; |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 71 | std::cout << "This message should go to standard out.\n"; |
| 72 | |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 73 | outfile.close(); |
Daniel Malea | d79ae05 | 2013-08-07 21:54:09 +0000 | [diff] [blame^] | 74 | return numberfn(); |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 75 | } |