Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
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
15 changes: 9 additions & 6 deletions include/aws/common/system_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ AWS_PUSH_SANE_WARNING_LEVEL
* Platform OS enumeration and their corresponding string representations.
*
* String mappings:
* - AWS_PLATFORM_OS_WINDOWS → "Windows" (Microsoft Windows family)
* - AWS_PLATFORM_OS_MAC → "macOS" (Apple desktop/laptop)
* - AWS_PLATFORM_OS_IOS → "iOS" (Apple mobile platforms, covers iOS, watchOS, tvOS,
* and other non-macOS Apple platforms)
* - AWS_PLATFORM_OS_ANDROID → "Android" (Google Android)
* - AWS_PLATFORM_OS_UNIX → "Unix" (Linux, BSD, other Unix-like)
* - AWS_PLATFORM_OS_WINDOWS → "Windows" (Microsoft Windows family)
* - AWS_PLATFORM_OS_MAC → "macOS" (Apple desktop/laptop)
* - AWS_PLATFORM_OS_IOS → "iOS" (Apple mobile devices)
* - AWS_PLATFORM_OS_TVOS → "tvOS" (Apple TV devices)
* - AWS_PLATFORM_OS_WATCHOS → "watchOS" (Apple Watch devices)
* - AWS_PLATFORM_OS_ANDROID → "Android" (Android)
* - AWS_PLATFORM_OS_UNIX → "Unix" (Linux, BSD, other Unix-like)
*/
enum aws_platform_os {
AWS_PLATFORM_OS_WINDOWS,
AWS_PLATFORM_OS_MAC,
AWS_PLATFORM_OS_IOS,
AWS_PLATFORM_OS_TVOS,
AWS_PLATFORM_OS_WATCHOS,
AWS_PLATFORM_OS_ANDROID,
AWS_PLATFORM_OS_UNIX,
};
Expand Down
6 changes: 5 additions & 1 deletion source/posix/system_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,12 @@ enum aws_platform_os aws_get_platform_build_os(void) {
#if defined(AWS_OS_MACOS)
return AWS_PLATFORM_OS_MAC;
// Other Apple platforms will be reported as iOS
#elif defined(AWS_OS_APPLE)
#elif defined(AWS_OS_IOS)
return AWS_PLATFORM_OS_IOS;
#elif defined(AWS_OS_TVOS)
return AWS_PLATFORM_OS_TVOS;
#elif defined(AWS_OS_WATCHOS)
return AWS_PLATFORM_OS_WATCHOS;
#elif defined(AWS_OS_ANDROID)
return AWS_PLATFORM_OS_ANDROID;
#else
Expand Down
64 changes: 50 additions & 14 deletions source/system_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,64 @@ size_t aws_system_environment_get_cpu_group_count(const struct aws_system_enviro
* - "Unix" - Unix-like systems (Linux, BSD, etc.)
* - "Unknown" - Fallback for unrecognized platforms
*/
AWS_STATIC_STRING_FROM_LITERAL(s_windows_str, "Windows");
AWS_STATIC_STRING_FROM_LITERAL(s_macos_str, "macOS");
AWS_STATIC_STRING_FROM_LITERAL(s_ios_str, "iOS");
AWS_STATIC_STRING_FROM_LITERAL(s_android_str, "Android");
AWS_STATIC_STRING_FROM_LITERAL(s_unix_str, "Unix");
AWS_STATIC_STRING_FROM_LITERAL(s_unknown_str, "Unknown");

static uint8_t s_platform_string_buffer[32];
static struct aws_byte_buf s_platform_buf =
{.buffer = s_platform_string_buffer, .capacity = sizeof(s_platform_string_buffer), .len = 0, .allocator = NULL};

struct aws_byte_cursor aws_get_platform_build_os_string(void) {
if (s_platform_buf.len != 0) {
return aws_byte_cursor_from_buf(&s_platform_buf);
}

enum aws_platform_os os = aws_get_platform_build_os();
struct aws_byte_cursor os_str;
struct aws_byte_cursor arch_str;

switch (os) {
case AWS_PLATFORM_OS_WINDOWS:
return aws_byte_cursor_from_string(s_windows_str);
os_str = aws_byte_cursor_from_c_str("Windows");
break;
case AWS_PLATFORM_OS_MAC:
return aws_byte_cursor_from_string(s_macos_str);
os_str = aws_byte_cursor_from_c_str("macOS");
break;
case AWS_PLATFORM_OS_IOS:
return aws_byte_cursor_from_string(s_ios_str);
os_str = aws_byte_cursor_from_c_str("iOS");
break;
case AWS_PLATFORM_OS_TVOS:
os_str = aws_byte_cursor_from_c_str("tvOS");
break;
case AWS_PLATFORM_OS_WATCHOS:
os_str = aws_byte_cursor_from_c_str("watchOS");
case AWS_PLATFORM_OS_ANDROID:
return aws_byte_cursor_from_string(s_android_str);
os_str = aws_byte_cursor_from_c_str("Android");
break;
case AWS_PLATFORM_OS_UNIX:
return aws_byte_cursor_from_string(s_unix_str);
os_str = aws_byte_cursor_from_c_str("Unix");
break;
default:
os_str = aws_byte_cursor_from_c_str("unknown");
AWS_LOGF_WARN(AWS_LS_COMMON_GENERAL, "Unknown platform OS enum value: %d", (int)os);
}
/* Handle invalid enum values */
AWS_LOGF_WARN(AWS_LS_COMMON_GENERAL, "Unknown platform OS enum value: %d", (int)os);
return aws_byte_cursor_from_string(s_unknown_str);

#ifdef AWS_ARCH_INTEL
arch_str = aws_byte_cursor_from_c_str("intel");
#elif defined(AWS_ARCH_INTEL_64)
arch_str = aws_byte_cursor_from_c_str("intel64");
#elif defined(AWS_ARCH_ARM64)
arch_str = aws_byte_cursor_from_c_str("arm64");
#elif defined(AWS_ARCH_ARM32)
arch_str = aws_byte_cursor_from_c_str("arm32");
#else
arch_str = aws_byte_cursor_from_c_str("unknown");
AWS_LOGF_WARN(AWS_LS_COMMON_GENERAL, "Unknown platform architecture.");
#endif

aws_byte_buf_reset(&s_platform_buf, false);
aws_byte_buf_append(&s_platform_buf, &os_str);
const struct aws_byte_cursor s_dash = aws_byte_cursor_from_c_str("-");
aws_byte_buf_append(&s_platform_buf, &s_dash);
aws_byte_buf_append(&s_platform_buf, &arch_str);

return aws_byte_cursor_from_buf(&s_platform_buf);
}
49 changes: 41 additions & 8 deletions tests/system_info_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ static int s_test_platform_build_os_fn(struct aws_allocator *allocator, void *ct

#if defined(AWS_OS_MACOS)
ASSERT_INT_EQUALS(build_os, AWS_PLATFORM_OS_MAC);
#elif defined(AWS_OS_APPLE)
#elif defined(AWS_OS_IOS)
ASSERT_INT_EQUALS(build_os, AWS_PLATFORM_OS_IOS);
#elif defined(AWS_OS_TVOS)
ASSERT_INT_EQUALS(build_os, AWS_PLATFORM_OS_TVOS);
#elif defined(AWS_OS_WATCHOS)
ASSERT_INT_EQUALS(build_os, AWS_PLATFORM_OS_WATCHOS);
#elif defined(AWS_OS_ANDROID)
ASSERT_INT_EQUALS(build_os, AWS_PLATFORM_OS_ANDROID);
#elif defined(_WIN32)
Expand All @@ -141,16 +145,45 @@ static int s_test_platform_build_os_string_fn(struct aws_allocator *allocator, v
ASSERT_TRUE(aws_byte_cursor_is_valid(&os_string));
ASSERT_TRUE(os_string.len > 0);

/* Verify OS-ARCH format */
struct aws_byte_cursor dash = aws_byte_cursor_from_c_str("-");
struct aws_byte_cursor found_dash;
ASSERT_SUCCESS(aws_byte_cursor_find_exact(&os_string, &dash, &found_dash));

struct aws_byte_cursor expected_os = aws_byte_cursor_from_c_str("Unknown-");

/* Verify OS part */
#if defined(AWS_OS_MACOS)
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "macOS"));
#elif defined(AWS_OS_APPLE)
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "iOS"));
expected_os = aws_byte_cursor_from_c_str("macOS-");
#elif defined(AWS_OS_IOS)
expected_os = aws_byte_cursor_from_c_str("iOS-");
#elif defined(AWS_OS_TVOS)
expected_os = aws_byte_cursor_from_c_str("tvOS-");
#elif defined(AWS_OS_WATCHOS)
expected_os = aws_byte_cursor_from_c_str("watchOS-");
#elif defined(AWS_OS_ANDROID)
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "Android"));
#elif defined(_WIN32)
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "Windows"));
expected_os = aws_byte_cursor_from_c_str("Android-");
#elif defined(AWS_OS_WINDOWS)
expected_os = aws_byte_cursor_from_c_str("Windows-");
#else
expected_os = aws_byte_cursor_from_c_str("Unix-");
#endif
ASSERT_TRUE(aws_byte_cursor_starts_with(&os_string, &expected_os));

/* Verify architecture part exists after dash */
size_t dash_pos = found_dash.ptr - os_string.ptr;
aws_byte_cursor_advance(&os_string, dash_pos + 1);

#if defined(AWS_ARCH_INTEL)
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "intel"));
#elif defined(AWS_ARCH_INTEL_64)
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "intel_64"));
#elif defined(AWS_ARCH_ARM64)
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "arm64"));
#elif defined(AWS_ARCH_ARM32)
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "arm32"));
#else
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "Unix"));
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&os_string, "unknown"));
#endif

return 0;
Expand Down