Add putenv test program 68/246168/2
authorINSUN PYO <insun.pyo@samsung.com>
Mon, 26 Oct 2020 08:04:18 +0000 (17:04 +0900)
committerINSUN PYO <insun.pyo@samsung.com>
Mon, 26 Oct 2020 08:11:20 +0000 (17:11 +0900)
Change-Id: I4765b24432eae3faf4b7ed36d1e6c8475838b85c

CMakeLists.txt
packaging/session-utils.spec
src/glibc-api-test/CMakeLists.txt [new file with mode: 0644]
src/glibc-api-test/putenv-test.c [new file with mode: 0644]

index 43df9ca..38d7177 100644 (file)
@@ -6,3 +6,4 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 ADD_SUBDIRECTORY(src/dbus-activation-stop-test)
 ADD_SUBDIRECTORY(src/dbus-send-receive-test)
 ADD_SUBDIRECTORY(src/dbus-policy-two-wellknownname-per-one-connection-test)
+ADD_SUBDIRECTORY(src/glibc-api-test)
index 5a166ef..ed66203 100644 (file)
@@ -49,6 +49,14 @@ This package provides bus policy test for twe wellknownname per one connection.
 
 
 ###############################################################################
+%package -n glibc-api-test
+Summary: glibc api test programs
+
+%description -n glibc-api-test
+This package provides glibc api test program
+
+
+###############################################################################
 %prep
 %setup -q
 
@@ -114,6 +122,12 @@ install -m 644 units/dbus-policy-two-wellknownname-per-one-connection-test-2.con
 
 
 ###############################################################################
+%files -n glibc-api-test
+%license LICENSE.Apache-2.0
+%manifest session-utils.manifest
+%{_bindir}/putenv-test
+
+###############################################################################
 %files -n g-debug-fatal-warnings
 %license LICENSE.Apache-2.0
 %manifest session-utils.manifest
diff --git a/src/glibc-api-test/CMakeLists.txt b/src/glibc-api-test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..29ed28b
--- /dev/null
@@ -0,0 +1,19 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(glibc-api-test C)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
+
+ADD_EXECUTABLE(putenv-test putenv-test.c)
+TARGET_LINK_LIBRARIES(putenv-test ${pkgs_LDFLAGS} -pie)
+
+INSTALL(TARGETS putenv-test DESTINATION bin
+               PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+               GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
diff --git a/src/glibc-api-test/putenv-test.c b/src/glibc-api-test/putenv-test.c
new file mode 100644 (file)
index 0000000..20cf0aa
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License 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 <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int main ()
+{
+    char buf[] = "AAA=aaa";
+
+    printf ("putenv(%s) result = %d\n", buf, putenv(buf));
+
+    buf[4] = 'b';
+    buf[5] = 'b';
+    buf[6] = 'b';
+
+    printf("AAA=%s\n", getenv("AAA"));
+}