File: process_test.c

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (83 lines) | stat: -rw-r--r-- 3,146 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/common/process.h>
#include <aws/common/string.h>
#include <aws/testing/aws_test_harness.h>

static int s_get_pid_sanity_check_test_fn(struct aws_allocator *allocator, void *ctx) {
    (void)allocator;
    (void)ctx;

    int pid = aws_get_pid();
    ASSERT_TRUE(pid > 0);

    return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(get_pid_sanity_check_test, s_get_pid_sanity_check_test_fn)

static int s_max_io_handles_sanity_check_test_fn(struct aws_allocator *allocator, void *ctx) {
    (void)allocator;
    (void)ctx;

    size_t soft_max_handles = aws_get_soft_limit_io_handles();
    ASSERT_TRUE(soft_max_handles > 0);
    size_t hard_max_handles = aws_get_hard_limit_io_handles();
    ASSERT_TRUE(hard_max_handles >= soft_max_handles);

    int error = aws_set_soft_limit_io_handles(soft_max_handles - 1);
    if (error) {
        /* this operation does nothing on some platforms such as windows, let's make sure that's why this failed. */
        ASSERT_UINT_EQUALS(AWS_ERROR_UNIMPLEMENTED, aws_last_error());
    } else {
        ASSERT_ERROR(AWS_ERROR_INVALID_ARGUMENT, aws_set_soft_limit_io_handles(hard_max_handles + 1));
    }

    return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(max_io_handles_sanity_check_test, s_max_io_handles_sanity_check_test_fn)

#ifdef _WIN32
AWS_STATIC_STRING_FROM_LITERAL(s_test_command, "echo {\"Version\": 1, \"AccessKeyId\": \"AccessKey123\"}");
#else
AWS_STATIC_STRING_FROM_LITERAL(s_test_command, "echo '{\"Version\": 1, \"AccessKeyId\": \"AccessKey123\"}'");
#endif
AWS_STATIC_STRING_FROM_LITERAL(s_expected_output, "{\"Version\": 1, \"AccessKeyId\": \"AccessKey123\"}");

static int s_run_command_test_success_fn(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;
    struct aws_run_command_options options = {.command = aws_string_c_str(s_test_command)};

    struct aws_run_command_result result;
    ASSERT_SUCCESS(aws_run_command_result_init(allocator, &result));
    ASSERT_SUCCESS(aws_run_command(allocator, &options, &result));
    ASSERT_TRUE(result.ret_code == 0);
    ASSERT_NOT_NULL(result.std_out);

    ASSERT_BIN_ARRAYS_EQUALS(
        result.std_out->bytes, result.std_out->len, s_expected_output->bytes, s_expected_output->len);

    aws_run_command_result_cleanup(&result);
    return AWS_OP_SUCCESS;
}
AWS_TEST_CASE(run_command_test_success, s_run_command_test_success_fn)

AWS_STATIC_STRING_FROM_LITERAL(s_bad_command, "/i/dont/know/what/is/this/command");
static int s_run_command_test_bad_command_fn(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;
    struct aws_run_command_options options = {.command = aws_string_c_str(s_bad_command)};

    struct aws_run_command_result result;
    ASSERT_SUCCESS(aws_run_command_result_init(allocator, &result));
    ASSERT_SUCCESS(aws_run_command(allocator, &options, &result));
    ASSERT_TRUE(result.ret_code != 0);
    ASSERT_NULL(result.std_out);

    aws_run_command_result_cleanup(&result);
    return AWS_OP_SUCCESS;
}
AWS_TEST_CASE(run_command_test_bad_command, s_run_command_test_bad_command_fn)