Skip to content
Open
Show file tree
Hide file tree
Changes from 12 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
59 changes: 45 additions & 14 deletions source/system_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,59 @@ 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_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);
}
39 changes: 32 additions & 7 deletions tests/system_info_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,41 @@ 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_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