Skip to content

Commit 916a197

Browse files
committed
add aws-greengrass-sdk-lite: new lightweight greengrass sdk, 0.2.0
1 parent b9cc45a commit 916a197

File tree

6 files changed

+603
-0
lines changed

6 files changed

+603
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
From: Amazon Q <q@amazon.com>
2+
Date: Mon, 4 Aug 2025 16:00:00 +0000
3+
Subject: [PATCH 1/2] Fix missing semicolon in crc32.c
4+
5+
Add missing semicolon after return statement in crc_step function.
6+
7+
Upstream-Status: Submitted [https://github.com/aws-greengrass/aws-greengrass-sdk-lite/pull/25]
8+
9+
Signed-off-by: Amazon Q <q@amazon.com>
10+
---
11+
src/crc32.c | 2 +-
12+
1 file changed, 1 insertion(+), 1 deletion(-)
13+
14+
diff --git a/src/crc32.c b/src/crc32.c
15+
index 1234567..abcdefg 100644
16+
--- a/src/crc32.c
17+
+++ b/src/crc32.c
18+
@@ -20,7 +20,7 @@
19+
#if HAS_BUILTIN_CRC
20+
21+
static uint32_t crc_step(uint32_t crc, uint8_t byte) {
22+
- return __builtin_rev_crc32_data8(crc, byte, 0x04C11DB7L)
23+
+ return __builtin_rev_crc32_data8(crc, byte, 0x04C11DB7L);
24+
}
25+
26+
#else
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
From: meta-aws <meta-aws@example.com>
2+
Date: Tue, 6 Aug 2025 15:25:00 +0000
3+
Subject: [PATCH 2/2] Build both static and shared libraries
4+
5+
This patch modifies the CMakeLists.txt to build both static and shared
6+
versions of libggl-sdk, allowing packages to choose the appropriate
7+
library type for their needs.
8+
9+
The shared library is built with proper versioning and both libraries
10+
are installed with appropriate targets. The shared library uses default
11+
symbol visibility to ensure public API symbols are exported.
12+
13+
Adds BUILD_SHARED_LIBS option (default ON) to conditionally build shared
14+
libraries, maintaining compatibility with static-only builds.
15+
16+
Disables LTO for shared library to avoid Clang issues with alloc_size
17+
attribute.
18+
19+
Upstream-Status: Submitted [https://github.com/aws-greengrass/aws-greengrass-sdk-lite/pull/26]
20+
Signed-off-by: meta-aws <meta-aws@example.com>
21+
22+
From: meta-aws <meta-aws@example.com>
23+
Date: Tue, 6 Aug 2025 15:25:00 +0000
24+
Subject: [PATCH 2/2] Build both static and shared libraries
25+
26+
This patch modifies the CMakeLists.txt to build both static and shared
27+
versions of libggl-sdk, allowing packages to choose the appropriate
28+
library type for their needs.
29+
30+
The shared library is built with proper versioning and both libraries
31+
are installed with appropriate targets. The shared library uses default
32+
symbol visibility to ensure public API symbols are exported.
33+
34+
Adds BUILD_SHARED_LIBS option (default ON) to conditionally build shared
35+
libraries, maintaining compatibility with static-only builds.
36+
37+
Disables LTO for shared library to avoid Clang issues with alloc_size
38+
attribute.
39+
40+
Upstream-Status: Submitted [https://github.com/aws-greengrass/aws-greengrass-sdk-lite/pull/26]
41+
Signed-off-by: meta-aws <meta-aws@example.com>
42+
43+
Index: aws-greengrass-sdk-lite-0.2.0/CMakeLists.txt
44+
===================================================================
45+
--- aws-greengrass-sdk-lite-0.2.0.orig/CMakeLists.txt
46+
+++ aws-greengrass-sdk-lite-0.2.0/CMakeLists.txt
47+
@@ -13,6 +13,8 @@ if(PROJECT_IS_TOP_LEVEL)
48+
49+
option(BUILD_SAMPLES "Build sample components" ON)
50+
51+
+ option(BUILD_SHARED_LIBS "Build shared libraries" ON)
52+
+
53+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
54+
55+
include(GNUInstallDirs)
56+
@@ -168,6 +170,38 @@ foreach(src ${SRCS})
57+
endforeach()
58+
59+
add_library(ggl-sdk STATIC ${SRCS})
60+
+
61+
+# Also build a shared version if requested
62+
+if(BUILD_SHARED_LIBS)
63+
+ add_library(ggl-sdk-shared SHARED ${SRCS})
64+
+ set_target_properties(
65+
+ ggl-sdk-shared
66+
+ PROPERTIES OUTPUT_NAME ggl-sdk
67+
+ VERSION 0.2.0
68+
+ SOVERSION 0)
69+
+
70+
+ # Apply same settings to shared library Note: Override -fvisibility=hidden for
71+
+ # shared library to export symbols. Disable LTO to avoid Clang issues with
72+
+ # alloc_size attribute.
73+
+ target_compile_options(
74+
+ ggl-sdk-shared
75+
+ PRIVATE -pthread
76+
+ -fno-strict-aliasing
77+
+ -std=gnu11
78+
+ -fno-semantic-interposition
79+
+ -fno-common
80+
+ -fno-unwind-tables
81+
+ -fno-asynchronous-unwind-tables
82+
+ -fvisibility=default
83+
+ -fno-lto
84+
+ -Wno-missing-braces)
85+
+ target_link_options(ggl-sdk-shared PRIVATE -fno-lto)
86+
+ target_compile_definitions(ggl-sdk-shared PRIVATE _GNU_SOURCE)
87+
+ target_include_directories(ggl-sdk-shared PRIVATE include priv_include)
88+
+ target_include_directories(ggl-sdk-shared SYSTEM INTERFACE include)
89+
+ target_compile_definitions(ggl-sdk-shared PRIVATE "GGL_MODULE=(\"ggl-sdk\")")
90+
+endif()
91+
+
92+
target_compile_options(ggl-sdk PRIVATE -pthread -fno-strict-aliasing -std=gnu11
93+
-Wno-missing-braces)
94+
target_compile_definitions(ggl-sdk PRIVATE _GNU_SOURCE)
95+
@@ -179,8 +213,19 @@ string(TOUPPER "${GGL_LOG_LEVEL}" log_le
96+
set(choose_level "$<IF:$<BOOL:${log_level}>,${log_level},DEBUG>")
97+
target_compile_definitions(ggl-sdk PUBLIC GGL_LOG_LEVEL=GGL_LOG_${choose_level})
98+
99+
+# Apply log level to shared library too
100+
+if(BUILD_SHARED_LIBS)
101+
+ target_compile_definitions(ggl-sdk-shared
102+
+ PUBLIC GGL_LOG_LEVEL=GGL_LOG_${choose_level})
103+
+endif()
104+
+
105+
if(PROJECT_IS_TOP_LEVEL)
106+
- install(TARGETS ggl-sdk)
107+
+ # Install both static and shared libraries
108+
+ if(BUILD_SHARED_LIBS)
109+
+ install(TARGETS ggl-sdk ggl-sdk-shared)
110+
+ else()
111+
+ install(TARGETS ggl-sdk)
112+
+ endif()
113+
114+
if(BUILD_SAMPLES)
115+
file(GLOB SAMPLE_DIRS CONFIGURE_DEPENDS "samples/*")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
# AWS Greengrass SDK Lite ptest runner
4+
# This script runs unit tests for the SDK components
5+
6+
PTEST_DIR=$(dirname $0)
7+
cd $PTEST_DIR
8+
9+
TOTAL_TESTS=0
10+
PASSED_TESTS=0
11+
FAILED_TESTS=0
12+
13+
run_test() {
14+
local test_name="$1"
15+
local test_binary="$2"
16+
17+
echo "Running $test_name..."
18+
TOTAL_TESTS=$((TOTAL_TESTS + 1))
19+
20+
if ./$test_binary; then
21+
echo "PASS: $test_name"
22+
PASSED_TESTS=$((PASSED_TESTS + 1))
23+
else
24+
echo "FAIL: $test_name"
25+
FAILED_TESTS=$((FAILED_TESTS + 1))
26+
fi
27+
echo
28+
}
29+
30+
echo "=== AWS Greengrass SDK Lite Test Suite ==="
31+
echo
32+
33+
# Run basic API tests
34+
run_test "Basic API Tests" "test-basic-api"
35+
36+
# Run JSON operation tests
37+
run_test "JSON Operations Tests" "test-json-ops"
38+
39+
echo "=== Test Summary ==="
40+
echo "Total tests: $TOTAL_TESTS"
41+
echo "Passed: $PASSED_TESTS"
42+
echo "Failed: $FAILED_TESTS"
43+
44+
if [ $FAILED_TESTS -eq 0 ]; then
45+
echo "All tests passed!"
46+
exit 0
47+
else
48+
echo "Some tests failed!"
49+
exit 1
50+
fi
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <assert.h>
5+
#include <ggl/error.h>
6+
#include <ggl/buffer.h>
7+
#include <ggl/object.h>
8+
9+
// Test counter
10+
static int test_count = 0;
11+
static int passed_count = 0;
12+
13+
#define TEST_ASSERT(condition, message) do { \
14+
test_count++; \
15+
if (condition) { \
16+
printf(" ✓ %s\n", message); \
17+
passed_count++; \
18+
} else { \
19+
printf(" ✗ %s\n", message); \
20+
} \
21+
} while(0)
22+
23+
void test_error_codes(void) {
24+
printf("Testing error codes...\n");
25+
26+
// Test that error codes are defined
27+
TEST_ASSERT(GGL_ERR_OK == 0, "GGL_ERR_OK should be 0");
28+
TEST_ASSERT(GGL_ERR_FAILURE != 0, "GGL_ERR_FAILURE should not be 0");
29+
TEST_ASSERT(GGL_ERR_INVALID != 0, "GGL_ERR_INVALID should not be 0");
30+
}
31+
32+
void test_buffer_creation(void) {
33+
printf("Testing buffer creation...\n");
34+
35+
// Test buffer from null-terminated string
36+
char test_str[] = "Hello, World!";
37+
GglBuffer buf = ggl_buffer_from_null_term(test_str);
38+
39+
TEST_ASSERT(buf.data != NULL, "Buffer data should not be NULL");
40+
TEST_ASSERT(buf.len == strlen(test_str), "Buffer length should match string length");
41+
TEST_ASSERT(memcmp(buf.data, test_str, buf.len) == 0, "Buffer content should match string");
42+
43+
// Test empty buffer
44+
char empty_str[] = "";
45+
GglBuffer empty_buf = ggl_buffer_from_null_term(empty_str);
46+
TEST_ASSERT(empty_buf.len == 0, "Empty buffer should have zero length");
47+
}
48+
49+
void test_object_types(void) {
50+
printf("Testing object types...\n");
51+
52+
// Test that object types are defined
53+
TEST_ASSERT(GGL_TYPE_NULL >= 0, "GGL_TYPE_NULL should be defined");
54+
TEST_ASSERT(GGL_TYPE_BOOLEAN >= 0, "GGL_TYPE_BOOLEAN should be defined");
55+
TEST_ASSERT(GGL_TYPE_I64 >= 0, "GGL_TYPE_I64 should be defined");
56+
TEST_ASSERT(GGL_TYPE_F64 >= 0, "GGL_TYPE_F64 should be defined");
57+
TEST_ASSERT(GGL_TYPE_BUF >= 0, "GGL_TYPE_BUF should be defined");
58+
TEST_ASSERT(GGL_TYPE_MAP >= 0, "GGL_TYPE_MAP should be defined");
59+
TEST_ASSERT(GGL_TYPE_LIST >= 0, "GGL_TYPE_LIST should be defined");
60+
}
61+
62+
void test_buffer_operations(void) {
63+
printf("Testing buffer operations...\n");
64+
65+
char str1[] = "Hello";
66+
char str2[] = "Hello";
67+
char str3[] = "World";
68+
69+
GglBuffer buf1 = ggl_buffer_from_null_term(str1);
70+
GglBuffer buf2 = ggl_buffer_from_null_term(str2);
71+
GglBuffer buf3 = ggl_buffer_from_null_term(str3);
72+
73+
// Test buffer equality
74+
TEST_ASSERT(buf1.len == buf2.len && memcmp(buf1.data, buf2.data, buf1.len) == 0,
75+
"Equal buffers should compare equal");
76+
TEST_ASSERT(!(buf1.len == buf3.len && memcmp(buf1.data, buf3.data, buf1.len) == 0),
77+
"Different buffers should not compare equal");
78+
}
79+
80+
void test_object_creation(void) {
81+
printf("Testing object creation...\n");
82+
83+
// Test null object
84+
GglObject null_obj = GGL_OBJ_NULL;
85+
TEST_ASSERT(ggl_obj_type(null_obj) == GGL_TYPE_NULL, "Null object should have NULL type");
86+
87+
// Test boolean object
88+
GglObject bool_obj = ggl_obj_bool(true);
89+
TEST_ASSERT(ggl_obj_type(bool_obj) == GGL_TYPE_BOOLEAN, "Boolean object should have BOOLEAN type");
90+
TEST_ASSERT(ggl_obj_into_bool(bool_obj) == true, "Boolean object should store true value");
91+
92+
// Test integer object
93+
GglObject int_obj = ggl_obj_i64(42);
94+
TEST_ASSERT(ggl_obj_type(int_obj) == GGL_TYPE_I64, "Integer object should have I64 type");
95+
TEST_ASSERT(ggl_obj_into_i64(int_obj) == 42, "Integer object should store correct value");
96+
97+
// Test float object
98+
GglObject float_obj = ggl_obj_f64(3.14159);
99+
TEST_ASSERT(ggl_obj_type(float_obj) == GGL_TYPE_F64, "Float object should have F64 type");
100+
double f_val = ggl_obj_into_f64(float_obj);
101+
TEST_ASSERT(f_val > 3.14 && f_val < 3.15, "Float object should store approximate value");
102+
}
103+
104+
int main(void) {
105+
printf("=== AWS Greengrass SDK Lite Basic API Tests ===\n\n");
106+
107+
test_error_codes();
108+
test_buffer_creation();
109+
test_object_types();
110+
test_buffer_operations();
111+
test_object_creation();
112+
113+
printf("\n=== Test Results ===\n");
114+
printf("Total tests: %d\n", test_count);
115+
printf("Passed: %d\n", passed_count);
116+
printf("Failed: %d\n", test_count - passed_count);
117+
118+
if (passed_count == test_count) {
119+
printf("All basic API tests passed!\n");
120+
return 0;
121+
} else {
122+
printf("Some basic API tests failed!\n");
123+
return 1;
124+
}
125+
}

0 commit comments

Comments
 (0)