diff --git a/include/aws/common/process.h b/include/aws/common/process.h new file mode 100644 index 000000000..083466b65 --- /dev/null +++ b/include/aws/common/process.h @@ -0,0 +1,26 @@ +#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); + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_PROCESS_H */ diff --git a/source/posix/process.c b/source/posix/process.c new file mode 100644 index 000000000..d2e9c8eec --- /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..aa7de43c6 --- /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(); +} 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..29d54906b --- /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)