| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/common/process.h> |
| 7 |
#include <aws/common/string.h> |
| 8 |
#include <aws/testing/aws_test_harness.h> |
| 9 |
|
| 10 |
static int s_get_pid_sanity_check_test_fn(struct aws_allocator *allocator, void *ctx) { |
| 11 |
(void)allocator; |
| 12 |
(void)ctx; |
| 13 |
|
| 14 |
int pid = aws_get_pid(); |
| 15 |
ASSERT_TRUE(pid > 0); |
| 16 |
|
| 17 |
return AWS_OP_SUCCESS; |
| 18 |
} |
| 19 |
|
| 20 |
AWS_TEST_CASE(get_pid_sanity_check_test, s_get_pid_sanity_check_test_fn) |
| 21 |
|
| 22 |
static int s_max_io_handles_sanity_check_test_fn(struct aws_allocator *allocator, void *ctx) { |
| 23 |
(void)allocator; |
| 24 |
(void)ctx; |
| 25 |
|
| 26 |
size_t soft_max_handles = aws_get_soft_limit_io_handles(); |
| 27 |
ASSERT_TRUE(soft_max_handles > 0); |
| 28 |
size_t hard_max_handles = aws_get_hard_limit_io_handles(); |
| 29 |
ASSERT_TRUE(hard_max_handles >= soft_max_handles); |
| 30 |
|
| 31 |
int error = aws_set_soft_limit_io_handles(soft_max_handles - 1); |
| 32 |
if (error) { |
| 33 |
|
| 34 |
ASSERT_UINT_EQUALS(AWS_ERROR_UNIMPLEMENTED, aws_last_error()); |
| 35 |
} else { |
| 36 |
ASSERT_ERROR(AWS_ERROR_INVALID_ARGUMENT, aws_set_soft_limit_io_handles(hard_max_handles + 1)); |
| 37 |
} |
| 38 |
|
| 39 |
return AWS_OP_SUCCESS; |
| 40 |
} |
| 41 |
|
| 42 |
AWS_TEST_CASE(max_io_handles_sanity_check_test, s_max_io_handles_sanity_check_test_fn) |
| 43 |
|
| 44 |
#ifdef _WIN32 |
| 45 |
AWS_STATIC_STRING_FROM_LITERAL(s_test_command, "echo {\"Version\": 1, \"AccessKeyId\": \"AccessKey123\"}"); |
| 46 |
#else |
| 47 |
AWS_STATIC_STRING_FROM_LITERAL(s_test_command, "echo '{\"Version\": 1, \"AccessKeyId\": \"AccessKey123\"}'"); |
| 48 |
#endif |
| 49 |
AWS_STATIC_STRING_FROM_LITERAL(s_expected_output, "{\"Version\": 1, \"AccessKeyId\": \"AccessKey123\"}"); |
| 50 |
|
| 51 |
static int s_run_command_test_success_fn(struct aws_allocator *allocator, void *ctx) { |
| 52 |
(void)ctx; |
| 53 |
struct aws_run_command_options options = {.command = aws_string_c_str(s_test_command)}; |
| 54 |
|
| 55 |
struct aws_run_command_result result; |
| 56 |
ASSERT_SUCCESS(aws_run_command_result_init(allocator, &result)); |
| 57 |
ASSERT_SUCCESS(aws_run_command(allocator, &options, &result)); |
| 58 |
ASSERT_TRUE(result.ret_code == 0); |
| 59 |
ASSERT_NOT_NULL(result.std_out); |
| 60 |
|
| 61 |
ASSERT_BIN_ARRAYS_EQUALS( |
| 62 |
result.std_out->bytes, result.std_out->len, s_expected_output->bytes, s_expected_output->len); |
| 63 |
|
| 64 |
aws_run_command_result_cleanup(&result); |
| 65 |
return AWS_OP_SUCCESS; |
| 66 |
} |
| 67 |
AWS_TEST_CASE(run_command_test_success, s_run_command_test_success_fn) |
| 68 |
|
| 69 |
AWS_STATIC_STRING_FROM_LITERAL(s_bad_command, "/i/dont/know/what/is/this/command"); |
| 70 |
static int s_run_command_test_bad_command_fn(struct aws_allocator *allocator, void *ctx) { |
| 71 |
(void)ctx; |
| 72 |
struct aws_run_command_options options = {.command = aws_string_c_str(s_bad_command)}; |
| 73 |
|
| 74 |
struct aws_run_command_result result; |
| 75 |
ASSERT_SUCCESS(aws_run_command_result_init(allocator, &result)); |
| 76 |
ASSERT_SUCCESS(aws_run_command(allocator, &options, &result)); |
| 77 |
ASSERT_TRUE(result.ret_code != 0); |
| 78 |
ASSERT_NULL(result.std_out); |
| 79 |
|
| 80 |
aws_run_command_result_cleanup(&result); |
| 81 |
return AWS_OP_SUCCESS; |
| 82 |
} |
| 83 |
AWS_TEST_CASE(run_command_test_bad_command, s_run_command_test_bad_command_fn) |