Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented x-platform getpid, started a process.h module for stuff l… #546

Merged
merged 3 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions include/aws/common/process.h
Original file line number Diff line number Diff line change
@@ -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/common/common.h>

AWS_EXTERN_C_BEGIN

AWS_COMMON_API int aws_get_pid(void);

JonathanHenson marked this conversation as resolved.
Show resolved Hide resolved
#endif /* AWS_COMMON_PROCESS_H */
23 changes: 23 additions & 0 deletions source/posix/process.c
Original file line number Diff line number Diff line change
@@ -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 <aws/common/process.h>

#include <unistd.h>
#include <sys/types.h>

int aws_get_pid(void) {
return (int)getpid();
}
21 changes: 21 additions & 0 deletions source/windows/process.c
Original file line number Diff line number Diff line change
@@ -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 <aws/common/process.h>

#include <process.h>

int aws_get_pid(void) {
return _getpid();
}
JonathanHenson marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions tests/process_test.c
Original file line number Diff line number Diff line change
@@ -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 <aws/testing/aws_test_harness.h>

#include <aws/common/process.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)