From 92a61fe4323a4931041091a16a2f5a1c780594e5 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Thu, 14 Nov 2019 13:19:15 -0800 Subject: [PATCH 1/3] Implemented x-platform getpid, started a process.h module for stuff like fork and process invoke etc... --- include/aws/common/process.h | 24 ++++++++++++++++++++++++ source/posix/process.c | 23 +++++++++++++++++++++++ source/windows/process.c | 21 +++++++++++++++++++++ tests/CMakeLists.txt | 2 ++ tests/process_test.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 include/aws/common/process.h create mode 100644 source/posix/process.c create mode 100644 source/windows/process.c create mode 100644 tests/process_test.c diff --git a/include/aws/common/process.h b/include/aws/common/process.h new file mode 100644 index 000000000..688b42304 --- /dev/null +++ b/include/aws/common/process.h @@ -0,0 +1,24 @@ +#ifndef AWS_COMMON_PROCESS_H +#define AWS_COMMON_PROCESS_H +/* + * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +AWS_EXTERN_C_BEGIN + +AWS_COMMON_API int aws_get_pid(void); + +#endif /* AWS_COMMON_PROCESS_H */ diff --git a/source/posix/process.c b/source/posix/process.c new file mode 100644 index 000000000..d4e5a5e0b --- /dev/null +++ b/source/posix/process.c @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include + +int aws_get_pid(void) { + return (int)getpid(); +} diff --git a/source/windows/process.c b/source/windows/process.c new file mode 100644 index 000000000..7941f5350 --- /dev/null +++ b/source/windows/process.c @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +#include + +#include + +int aws_get_pid(void) { + return _getpid(); +} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bbe51816a..836e779da 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -385,6 +385,8 @@ add_test_case(test_background_log_channel_all) add_test_case(test_pipeline_logger_unformatted_test) add_test_case(test_pipeline_logger_formatted_test) +add_test_case(get_pid_sanity_check_test) + generate_test_driver(${CMAKE_PROJECT_NAME}-tests) if (NOT MSVC AND NOT LEGACY_COMPILER_SUPPORT) diff --git a/tests/process_test.c b/tests/process_test.c new file mode 100644 index 000000000..263561bea --- /dev/null +++ b/tests/process_test.c @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include + +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) \ No newline at end of file From 070265a664a9e9fc3804cb17ab8c9eabd7c5a828 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Thu, 14 Nov 2019 13:34:27 -0800 Subject: [PATCH 2/3] Updated formatting and closed extern block. --- include/aws/common/process.h | 2 ++ source/posix/process.c | 2 +- source/windows/process.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/aws/common/process.h b/include/aws/common/process.h index 688b42304..083466b65 100644 --- a/include/aws/common/process.h +++ b/include/aws/common/process.h @@ -21,4 +21,6 @@ AWS_EXTERN_C_BEGIN AWS_COMMON_API int aws_get_pid(void); +AWS_EXTERN_C_END + #endif /* AWS_COMMON_PROCESS_H */ diff --git a/source/posix/process.c b/source/posix/process.c index d4e5a5e0b..d2e9c8eec 100644 --- a/source/posix/process.c +++ b/source/posix/process.c @@ -15,8 +15,8 @@ #include -#include #include +#include int aws_get_pid(void) { return (int)getpid(); diff --git a/source/windows/process.c b/source/windows/process.c index 7941f5350..aa7de43c6 100644 --- a/source/windows/process.c +++ b/source/windows/process.c @@ -18,4 +18,4 @@ int aws_get_pid(void) { return _getpid(); -} \ No newline at end of file +} From a928c72b9fc58bd371ab9ec95b84405d1dfd1185 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Thu, 14 Nov 2019 13:35:24 -0800 Subject: [PATCH 3/3] Forgot a newline. --- tests/process_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/process_test.c b/tests/process_test.c index 263561bea..29d54906b 100644 --- a/tests/process_test.c +++ b/tests/process_test.c @@ -27,4 +27,4 @@ static int s_get_pid_sanity_check_test_fn(struct aws_allocator *allocator, void return AWS_OP_SUCCESS; } -AWS_TEST_CASE(get_pid_sanity_check_test, s_get_pid_sanity_check_test_fn) \ No newline at end of file +AWS_TEST_CASE(get_pid_sanity_check_test, s_get_pid_sanity_check_test_fn)