Integrate system-info-testplugin with system-info-test 57/237957/4
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 7 Jul 2020 02:50:27 +0000 (11:50 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 13 Aug 2020 08:16:56 +0000 (17:16 +0900)
- src/test -> test/api
- src/testplugin -> test/plugin

Change-Id: I315479656b8cf2a32394fd35380f2fcb1cbc9a51
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
13 files changed:
CMakeLists.txt
packaging/capi-system-info.spec
src/test/CMakeLists.txt [deleted file]
src/test/system_info_external_plugin_test.sh.in [deleted file]
src/test/system_info_test.c [deleted file]
src/testplugin/CMakeLists.txt [deleted file]
src/testplugin/plugin_test.c [deleted file]
test/CMakeLists.txt [new file with mode: 0755]
test/api/CMakeLists.txt [new file with mode: 0755]
test/api/system_info_test.c [new file with mode: 0755]
test/plugin/CMakeLists.txt [new file with mode: 0755]
test/plugin/plugin_test.c [new file with mode: 0644]
test/plugin/system_info_external_plugin_test.sh.in [new file with mode: 0755]

index 7ee492e5446fe98cdab90d6217db70c45ef4a971..a33601168120b8b284ca4a271eb4b9529211274e 100644 (file)
@@ -86,8 +86,7 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/system_info_intf.h DESTINATION
 
 ADD_SUBDIRECTORY(src/tizenid)
 ADD_SUBDIRECTORY(src/init_db)
-ADD_SUBDIRECTORY(src/test)
-ADD_SUBDIRECTORY(src/testplugin)
+ADD_SUBDIRECTORY(test)
 
 IF(UNIX)
 
index 2c8574a4ea348f1965ad40ad25d024d614929a16..97c2702c2a892176f729da1888cf8fb686912dae 100644 (file)
@@ -26,21 +26,13 @@ Requires: %{name} = %{version}-%{release}
 
 %description devel
 
-%package testplugin
-Summary:  System-info test plugin package
-Group:    Development/System
-
-%description testplugin
-A System Information test plugins
-
 %package test
 Summary:  System-info test package
 Group:    Development/System
 Requires: %{name}
-Requires: %{name}-testplugin
 
 %description test
-A System Information library test tool
+A System Information test tool
 
 %if 0%{?gcov:1}
 %package -n system-info-gcov
@@ -133,15 +125,13 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
 %{_libdir}/pkgconfig/*.pc
 %{_libdir}/libcapi-system-info.so
 
-%files testplugin
-%{_libdir}/libsystem_info_plugins/libsystem_info_test_plugin.so
-%{_libdir}/libsystem_info_plugins/libsystem_info_test_plugin2.so
-
 %files test
+# API test
 %{_bindir}/system_info_test
-%{_bindir}/system_info_external_plugin_test.sh
+# Plugin test
 %attr(0755,root,-) %{_bindir}/system_info_external_plugin_test.sh
-
+%{_libdir}/libsystem_info_plugins/libsystem_info_test_plugin.so
+%{_libdir}/libsystem_info_plugins/libsystem_info_test_plugin2.so
 
 %if 0%{?gcov:1}
 %files -n system-info-gcov
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
deleted file mode 100755 (executable)
index 7aa53d3..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-
-SET(SYSTEM_INFO_TEST "system_info_test")
-SET(SRCS ${CMAKE_SOURCE_DIR}/src/test/system_info_test.c)
-
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
-
-FOREACH(flag ${SYSTEM_INFO_TEST_pkgs_CFLAGS})
-       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions -fpie")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-
-ADD_EXECUTABLE(${SYSTEM_INFO_TEST} ${SRCS})
-ADD_DEPENDENCIES(${SYSTEM_INFO_TEST} ${fw_name})
-TARGET_LINK_LIBRARIES(${SYSTEM_INFO_TEST} ${SYSTEM_INFO_TEST_pkgs_LDFLAGS} "-L${CMAKE_SOURCE_DIR} -lcapi-system-info")
-
-SET(TEST_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/system_info_external_plugin_test.sh)
-CONFIGURE_FILE(${TEST_SCRIPT}.in ${TEST_SCRIPT} @ONLY)
-
-INSTALL(TARGETS ${SYSTEM_INFO_TEST} DESTINATION bin)
-INSTALL(FILES ${TEST_SCRIPT} DESTINATION bin)
-
diff --git a/src/test/system_info_external_plugin_test.sh.in b/src/test/system_info_external_plugin_test.sh.in
deleted file mode 100755 (executable)
index e5a6839..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-#!/bin/bash
-
-function test_key_type_string_cmd() {
-       cmd_result="$(system_info_test -g custom -t string -k sysinfotest_ks)"
-       name="'$FUNCNAME'"
-}
-
-function test_string_not_int_cmd() {
-       cmd_result="$(system_info_test -g custom -t int -k sysinfotest_ks)"
-       name="'$FUNCNAME'"
-}
-
-function test_string_not_double_cmd() {
-       cmd_result="$(system_info_test -g custom -t double -k sysinfotest_ks)"
-       name="'$FUNCNAME'"
-}
-
-function test_string_not_bool_cmd() {
-       cmd_result="$(system_info_test -g custom -t bool -k sysinfotest_ks)"
-       name="'$FUNCNAME'"
-}
-
-function test_key_type_int_cmd() {
-       cmd_result="$(system_info_test -g custom -t int -k sysinfotest_ki)"
-       name="'$FUNCNAME'"
-}
-
-function test_key_type_double_cmd() {
-       cmd_result="$(system_info_test -g custom -t double -k sysinfotest_kd)"
-       name="'$FUNCNAME'"
-}
-
-function test_key_type_bool_cmd() {
-       cmd_result="$(system_info_test -g custom -t bool -k sysinfotest_kb)"
-       name="'$FUNCNAME'"
-}
-
-function test_bool_not_string_cmd() {
-       cmd_result="$(system_info_test -g custom -t string -k sysinfotest_kb)"
-       name="'$FUNCNAME'"
-}
-
-function test_bool_not_int_cmd() {
-       cmd_result="$(system_info_test -g custom -t int -k sysinfotest_kb)"
-       name="'$FUNCNAME'"
-}
-
-function test_bool_not_double_cmd() {
-       cmd_result="$(system_info_test -g custom -t double -k sysinfotest_kb)"
-       name="'$FUNCNAME'"
-}
-
-function test_second_plugin_str_cmd() {
-       cmd_result="$(system_info_test -g custom -t string -k sysinfotest_vks_custom)"
-       name="'$FUNCNAME'"
-}
-
-function test_right_plugin_str_cmd() {
-       cmd_result="$(system_info_test -g custom -t string -k sysinfotest_kvs)"
-       name="'$FUNCNAME'"
-}
-
-function get_cmd_result() {
-       check_result="$(echo $1 | cut -d'(' -f6 | cut -d')' -f1)"
-}
-
-function check_file_exists() {
-       cmd_result="$(test -s $1 && echo 'exists' || echo 'not')"
-       name="'$FUNCNAME' $1"
-}
-
-function check_command_exists() {
-       command_exists="$(type -p system_info_test)"
-}
-
-function check_result() {
-       local test_cmd=$1
-       local expected_result=$2
-
-       $test_cmd
-       get_cmd_result "$cmd_result"
-
-       #check if a variable is a number (formating cmd output)
-       re='^[+-]?[0-9]+([.][0-9]+)?$'
-       if [[ $check_result =~ $re ]] ; then
-               check_result="$(printf '%.2f' $check_result)"
-               if [[ $expected_result =~ $re ]] ; then
-                       expected_result="$(printf '%.2f' $expected_result)"
-               fi
-       fi
-
-       sign='='
-       nsign='!'
-       if [[ $# -ge 3 && $3 == '!' ]]; then
-               nsign=$sign
-               sign=$3
-       fi
-       if [[ $check_result == '' ]]; then
-               check_result='EMPTY_RESULT'
-       fi
-       if [[ ( $check_result != 'EMPTY_RESULT' && ( $sign == '!' && "$check_result" != "$expected_result" ) || ( "$check_result" == "$expected_result" ) ) ]]; then
-               echo -e '\033[32m[' ' OK ' ']\e[0m' "$name:\t" "$sign('$expected_result')"
-       else
-               echo -e '\033[31m[' 'FAIL' ']\e[0m' "$name:\t" "('\033[31m$check_result\e[0m'" "$nsign=" "'\033[32m$expected_result\e[0m')"
-               return_code=1
-       fi
-}
-
-check_command_exists result
-if [ -z "$command_exists" ]; then
-       exit 1
-fi
-
-return_code=0
-
-PLUGIN_FILE='@PLUGIN_DIR@/libsystem_info_plugins/libsystem_info_test_plugin.so'
-check_result "check_file_exists $PLUGIN_FILE" 'exists'
-PLUGIN_FILE='@PLUGIN_DIR@/libsystem_info_plugins/libsystem_info_test_plugin2.so'
-check_result "check_file_exists $PLUGIN_FILE" 'exists'
-
-check_result test_key_type_string_cmd 'plugin'
-check_result test_string_not_int_cmd 'ERROR : -22'
-check_result test_string_not_double_cmd 'ERROR : -22'
-check_result test_string_not_bool_cmd 'ERROR : -22'
-check_result test_key_type_int_cmd '1'
-check_result test_key_type_double_cmd '2.0'
-check_result test_key_type_bool_cmd '1'
-check_result test_bool_not_string_cmd 'ERROR : -22'
-check_result test_bool_not_int_cmd 'ERROR : -22'
-check_result test_bool_not_double_cmd 'ERROR : -22'
-check_result test_second_plugin_str_cmd 'various key'
-check_result test_right_plugin_str_cmd 'first_in_lexicographical_order'
-check_result test_right_plugin_str_cmd 'second_in_lexicographical_order' '!'
-check_result test_right_plugin_str_cmd 'ERROR : -22' '!'
-
-exit $return_code
diff --git a/src/test/system_info_test.c b/src/test/system_info_test.c
deleted file mode 100755 (executable)
index 0f308d3..0000000
+++ /dev/null
@@ -1,261 +0,0 @@
-#include <errno.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <system_info.h>
-
-#define SUCCESS 0
-
-#define OPT_MAX 16
-#define KEY_MAX 256
-
-#define RUNTIME_ENV "RUNTIME_TYPE"
-
-#define DEFAULT_OPT 0
-
-#define CONVERT_ARGUMENT(input_str, input_str_len, output_num, table)  \
-{      \
-       int __idx;      \
-       bool __is_converted = false;    \
-       for (__idx = 0; __idx < sizeof(table) / sizeof(struct str_num_table); __idx++) {        \
-               if (!strncmp(input_str, table[__idx].str, strlen(table[__idx].str) + 1)) {      \
-                       output_num = table[__idx].num;  \
-                       __is_converted = true;  \
-                       break;  \
-               }       \
-       }       \
-       if (!__is_converted) {  \
-               if (input_str[0] == '\0') {     \
-                       output_num = table[DEFAULT_OPT].num;    \
-                       strncpy(input_str, table[DEFAULT_OPT].str, input_str_len - 1);  \
-                       input_str[input_str_len - 1] = '\0'; \
-               } else {        \
-                       printf("Invalid argument %s\n\n", input_str);   \
-                       show_help();    \
-                       return EINVAL;  \
-               }       \
-       }       \
-}
-
-enum tag {
-       TAG_PLATFORM,
-       TAG_CUSTOM,
-       TAG_MAX
-};
-
-enum type {
-       TYPE_BOOL,
-       TYPE_INT,
-       TYPE_DOUBLE,
-       TYPE_STRING,
-       TYPE_MAX
-};
-
-enum runtime {
-       RUNTIME_C,
-       RUNTIME_WEB,
-       RUNTIME_DOTNET,
-       RUNTIME_MAX
-};
-
-struct str_num_table {
-       const char *str;
-       int num;
-};
-
-/**
- * @remarks  If there is no input, set to the first element.
- *           It means the first element is default value.
- *           To disable default value, check essential options.
- */
-
-struct str_num_table tag_table[TAG_MAX] = {
-       { "platform", TAG_PLATFORM },
-       { "custom",   TAG_CUSTOM },
-};
-
-struct str_num_table type_table[TYPE_MAX] = {
-       { "bool",   TYPE_BOOL },
-       { "int",    TYPE_INT },
-       { "double", TYPE_DOUBLE },
-       { "string", TYPE_STRING },
-};
-
-struct str_num_table runtime_table[RUNTIME_MAX] = {
-       { "c",      RUNTIME_C },
-       { "web",    RUNTIME_WEB },
-       { "dotnet", RUNTIME_DOTNET },
-};
-
-static char     tag_str[OPT_MAX];
-static enum tag tag_num;
-
-static char      type_str[OPT_MAX];
-static enum type type_num;
-
-static char key[KEY_MAX];
-
-static char         runtime_str[OPT_MAX];
-static enum runtime runtime_num;
-
-static void show_help(void)
-{
-       printf("system_info_test [OPTIONS]\n");
-       printf("  -g TAG      System info tag to read (platform/custom)\n");
-       printf("              (Optional, default value is platform)\n");
-       printf("  -t TYPE     System info type to read (bool/int/double/string)\n");
-       printf("              (Essential)\n");
-       printf("  -k KEY      System info key to read\n");
-       printf("              (Essential)\n");
-       printf("  -r RUNTIME  Runtime type (c/web/dotnet)\n");
-       printf("              (Optional, default value is c)\n");
-       printf("\n");
-       printf("  -h       Show this message\n");
-       printf("\n");
-       printf("Example:\n");
-       printf("  system_info_test -g platform -t string -k tizen.org/system/platform.name -r c\n");
-}
-
-int main(int argc, char *argv[])
-{
-       int ret;
-       int opt;
-
-       bool val_bool;
-       int val_int;
-       double val_double;
-       char *val_string = NULL;
-
-       /* Parse arguments */
-       while ((opt = getopt(argc, argv, "g:t:k:r:h")) != -1) {
-               switch (opt) {
-               case 'g':
-                       snprintf(tag_str, OPT_MAX, "%s", optarg);
-                       break;
-               case 't':
-                       snprintf(type_str, OPT_MAX, "%s", optarg);
-                       break;
-               case 'k':
-                       snprintf(key, KEY_MAX, "%s", optarg);
-                       break;
-               case 'r':
-                       snprintf(runtime_str, OPT_MAX, "%s", optarg);
-                       break;
-               case 'h':
-                       show_help();
-                       return SUCCESS;
-               default:
-                       show_help();
-                       return EINVAL;
-               }
-       }
-
-       /* Check whether essential options are inputted */
-       if (type_str[0] == '\0' || key[0] == '\0') {
-               printf("Essential options aren't inputted\n\n");
-               show_help();
-               return EINVAL;
-       }
-
-       /* Convert string arguments into the enum value */
-       CONVERT_ARGUMENT(tag_str, sizeof(tag_str), tag_num, tag_table);
-       CONVERT_ARGUMENT(type_str, sizeof(type_str), type_num, type_table);
-       CONVERT_ARGUMENT(runtime_str, sizeof(runtime_str), runtime_num, runtime_table);
-
-       /* Set the runtime environment value */
-       switch (runtime_num) {
-       case RUNTIME_C:
-               ret = setenv(RUNTIME_ENV, "capp", 1);
-               break;
-       case RUNTIME_WEB:
-               ret = setenv(RUNTIME_ENV, "webapp", 1);
-               break;
-       case RUNTIME_DOTNET:
-               ret = setenv(RUNTIME_ENV, "dotnet", 1);
-               break;
-       default:
-               printf("Failed to convert runtime argument\n");
-               return EIO;
-               break;
-       }
-
-       if (ret != SUCCESS) {
-               printf("setenv failed : %m\n");
-               return errno;
-       }
-
-       printf("TAG(%s), TYPE(%s), RUNTIME(%s), KEY(%s), RESULT(",
-                       tag_str, type_str, runtime_str, key);
-
-       /* Call appropriate system-info API and print result */
-       switch (tag_num) {
-       case TAG_PLATFORM:
-               switch (type_num) {
-               case TYPE_BOOL:
-                       ret = system_info_get_platform_bool(key, &val_bool);
-                       if (ret == SYSTEM_INFO_ERROR_NONE)
-                               printf("%d", val_bool);
-                       break;
-               case TYPE_INT:
-                       ret = system_info_get_platform_int(key, &val_int);
-                       if (ret == SYSTEM_INFO_ERROR_NONE)
-                               printf("%d", val_int);
-                       break;
-               case TYPE_DOUBLE:
-                       ret = system_info_get_platform_double(key, &val_double);
-                       if (ret == SYSTEM_INFO_ERROR_NONE)
-                               printf("%lf", val_double);
-                       break;
-               case TYPE_STRING:
-                       ret = system_info_get_platform_string(key, &val_string);
-                       if (ret == SYSTEM_INFO_ERROR_NONE)
-                               printf("%s", val_string);
-                       break;
-               default:
-                       ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
-                       break;
-               }
-               break;
-       case TAG_CUSTOM:
-               switch (type_num) {
-               case TYPE_BOOL:
-                       ret = system_info_get_custom_bool(key, &val_bool);
-                       if (ret == SYSTEM_INFO_ERROR_NONE)
-                               printf("%d", val_bool);
-                       break;
-               case TYPE_INT:
-                       ret = system_info_get_custom_int(key, &val_int);
-                       if (ret == SYSTEM_INFO_ERROR_NONE)
-                               printf("%d", val_int);
-                       break;
-               case TYPE_DOUBLE:
-                       ret = system_info_get_custom_double(key, &val_double);
-                       if (ret == SYSTEM_INFO_ERROR_NONE)
-                               printf("%lf", val_double);
-                       break;
-               case TYPE_STRING:
-                       ret = system_info_get_custom_string(key, &val_string);
-                       if (ret == SYSTEM_INFO_ERROR_NONE)
-                               printf("%s", val_string);
-                       break;
-               default:
-                       ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
-                       break;
-               }
-               break;
-       default:
-               ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
-               break;
-       }
-
-       if (ret != SYSTEM_INFO_ERROR_NONE) {
-               printf("ERROR : %d", ret);
-       }
-
-       printf(")\n");
-
-       return SUCCESS;
-}
diff --git a/src/testplugin/CMakeLists.txt b/src/testplugin/CMakeLists.txt
deleted file mode 100755 (executable)
index 8f9d45a..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-SET(SI_PLUGIN "system_info_test_plugin")
-
-SET(SRCS ${CMAKE_SOURCE_DIR}/src/testplugin/plugin_test.c)
-
-INCLUDE_DIRECTORIES(include)
-
-ADD_LIBRARY(${SI_PLUGIN} MODULE ${SRCS})
-SET_TARGET_PROPERTIES(${SI_PLUGIN} PROPERTIES COMPILE_FLAGS -DPLUGIN_FIRST)
-ADD_LIBRARY(${SI_PLUGIN}2 MODULE ${SRCS})
-
-INSTALL(TARGETS ${SI_PLUGIN} DESTINATION ${LIB_INSTALL_DIR}/libsystem_info_plugins)
-INSTALL(TARGETS ${SI_PLUGIN}2 DESTINATION ${LIB_INSTALL_DIR}/libsystem_info_plugins)
diff --git a/src/testplugin/plugin_test.c b/src/testplugin/plugin_test.c
deleted file mode 100644 (file)
index 5824b80..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <string.h>
-#include <system_info_intf.h>
-
-#include "system_info_type.h"
-
-#define VALUES_COUNT (sizeof value_descriptors / sizeof *value_descriptors)
-
-#ifdef PLUGIN_FIRST
-       #define PLUGIN_STRING_VALUE "first_in_lexicographical_order"
-       #define PLUGIN_STRING_KEY ""
-#else
-       #define PLUGIN_STRING_VALUE "second_in_lexicographical_order"
-       #define PLUGIN_STRING_KEY "_custom"
-#endif
-
-const struct entity {
-       const char *key;
-       const char *type;
-       const char *value;
-} value_descriptors[] = {
-       { "sysinfotest_kvs", TYPE_STR, PLUGIN_STRING_VALUE },
-       { "sysinfotest_vks" PLUGIN_STRING_KEY, TYPE_STR, "various key" },
-       { "sysinfotest_ks", TYPE_STR, "plugin" },
-       { "sysinfotest_ki", TYPE_INT, "1" },
-       { "sysinfotest_kd", TYPE_DBL, "2.0" },
-       { "sysinfotest_kb", TYPE_BOOL, "true" }
-};
-
-static int get_value(const char *tag, const char *key, const char *type, char *buf, unsigned int len)
-{
-       if (key && type)
-               for (size_t i = 0; i < VALUES_COUNT; ++i)
-                       if (!strcmp(key, value_descriptors[i].key) && !strcmp(type, value_descriptors[i].type)) {
-                               if (!strncpy(buf, value_descriptors[i].value, len))
-                                       return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
-                               return SYSTEM_INFO_ERROR_NONE;
-                       }
-       return SYSTEM_INFO_ERROR_IO_ERROR;
-}
-
-static int get_type(const char *tag, const char *key, char *buf, unsigned int len)
-{
-       if (key)
-               for (size_t i = 0; i < VALUES_COUNT; ++i)
-                       if (!strcmp(key, value_descriptors[i].key)) {
-                               if (!strncpy(buf, value_descriptors[i].type, len))
-                                       return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
-                               return SYSTEM_INFO_ERROR_NONE;
-                       }
-       return SYSTEM_INFO_ERROR_IO_ERROR;
-}
-
-const system_info_external_plugin_interface intf = {
-       .get_value_external = get_value,
-       .get_type_external = get_type,
-};
-
-__attribute__ ((visibility ("default")))
-const system_info_external_plugin_interface *system_info_get_external_plugin_interface(void)
-{
-       return &intf;
-}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..cca96c4
--- /dev/null
@@ -0,0 +1,10 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET(TESTS
+       api
+       plugin
+)
+
+FOREACH(TEST ${TESTS})
+       ADD_SUBDIRECTORY(${TEST})
+ENDFOREACH(TEST)
diff --git a/test/api/CMakeLists.txt b/test/api/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..1ec0ed8
--- /dev/null
@@ -0,0 +1,22 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET(SYSTEM_INFO_TEST "system_info_test")
+SET(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/system_info_test.c)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+
+FOREACH(flag ${SYSTEM_INFO_TEST_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions -fpie")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+ADD_EXECUTABLE(${SYSTEM_INFO_TEST} ${SRCS})
+ADD_DEPENDENCIES(${SYSTEM_INFO_TEST} ${fw_name})
+TARGET_LINK_LIBRARIES(${SYSTEM_INFO_TEST} ${SYSTEM_INFO_TEST_pkgs_LDFLAGS} "-L${CMAKE_SOURCE_DIR} -lcapi-system-info")
+
+INSTALL(TARGETS ${SYSTEM_INFO_TEST} DESTINATION bin)
diff --git a/test/api/system_info_test.c b/test/api/system_info_test.c
new file mode 100755 (executable)
index 0000000..0f308d3
--- /dev/null
@@ -0,0 +1,261 @@
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <system_info.h>
+
+#define SUCCESS 0
+
+#define OPT_MAX 16
+#define KEY_MAX 256
+
+#define RUNTIME_ENV "RUNTIME_TYPE"
+
+#define DEFAULT_OPT 0
+
+#define CONVERT_ARGUMENT(input_str, input_str_len, output_num, table)  \
+{      \
+       int __idx;      \
+       bool __is_converted = false;    \
+       for (__idx = 0; __idx < sizeof(table) / sizeof(struct str_num_table); __idx++) {        \
+               if (!strncmp(input_str, table[__idx].str, strlen(table[__idx].str) + 1)) {      \
+                       output_num = table[__idx].num;  \
+                       __is_converted = true;  \
+                       break;  \
+               }       \
+       }       \
+       if (!__is_converted) {  \
+               if (input_str[0] == '\0') {     \
+                       output_num = table[DEFAULT_OPT].num;    \
+                       strncpy(input_str, table[DEFAULT_OPT].str, input_str_len - 1);  \
+                       input_str[input_str_len - 1] = '\0'; \
+               } else {        \
+                       printf("Invalid argument %s\n\n", input_str);   \
+                       show_help();    \
+                       return EINVAL;  \
+               }       \
+       }       \
+}
+
+enum tag {
+       TAG_PLATFORM,
+       TAG_CUSTOM,
+       TAG_MAX
+};
+
+enum type {
+       TYPE_BOOL,
+       TYPE_INT,
+       TYPE_DOUBLE,
+       TYPE_STRING,
+       TYPE_MAX
+};
+
+enum runtime {
+       RUNTIME_C,
+       RUNTIME_WEB,
+       RUNTIME_DOTNET,
+       RUNTIME_MAX
+};
+
+struct str_num_table {
+       const char *str;
+       int num;
+};
+
+/**
+ * @remarks  If there is no input, set to the first element.
+ *           It means the first element is default value.
+ *           To disable default value, check essential options.
+ */
+
+struct str_num_table tag_table[TAG_MAX] = {
+       { "platform", TAG_PLATFORM },
+       { "custom",   TAG_CUSTOM },
+};
+
+struct str_num_table type_table[TYPE_MAX] = {
+       { "bool",   TYPE_BOOL },
+       { "int",    TYPE_INT },
+       { "double", TYPE_DOUBLE },
+       { "string", TYPE_STRING },
+};
+
+struct str_num_table runtime_table[RUNTIME_MAX] = {
+       { "c",      RUNTIME_C },
+       { "web",    RUNTIME_WEB },
+       { "dotnet", RUNTIME_DOTNET },
+};
+
+static char     tag_str[OPT_MAX];
+static enum tag tag_num;
+
+static char      type_str[OPT_MAX];
+static enum type type_num;
+
+static char key[KEY_MAX];
+
+static char         runtime_str[OPT_MAX];
+static enum runtime runtime_num;
+
+static void show_help(void)
+{
+       printf("system_info_test [OPTIONS]\n");
+       printf("  -g TAG      System info tag to read (platform/custom)\n");
+       printf("              (Optional, default value is platform)\n");
+       printf("  -t TYPE     System info type to read (bool/int/double/string)\n");
+       printf("              (Essential)\n");
+       printf("  -k KEY      System info key to read\n");
+       printf("              (Essential)\n");
+       printf("  -r RUNTIME  Runtime type (c/web/dotnet)\n");
+       printf("              (Optional, default value is c)\n");
+       printf("\n");
+       printf("  -h       Show this message\n");
+       printf("\n");
+       printf("Example:\n");
+       printf("  system_info_test -g platform -t string -k tizen.org/system/platform.name -r c\n");
+}
+
+int main(int argc, char *argv[])
+{
+       int ret;
+       int opt;
+
+       bool val_bool;
+       int val_int;
+       double val_double;
+       char *val_string = NULL;
+
+       /* Parse arguments */
+       while ((opt = getopt(argc, argv, "g:t:k:r:h")) != -1) {
+               switch (opt) {
+               case 'g':
+                       snprintf(tag_str, OPT_MAX, "%s", optarg);
+                       break;
+               case 't':
+                       snprintf(type_str, OPT_MAX, "%s", optarg);
+                       break;
+               case 'k':
+                       snprintf(key, KEY_MAX, "%s", optarg);
+                       break;
+               case 'r':
+                       snprintf(runtime_str, OPT_MAX, "%s", optarg);
+                       break;
+               case 'h':
+                       show_help();
+                       return SUCCESS;
+               default:
+                       show_help();
+                       return EINVAL;
+               }
+       }
+
+       /* Check whether essential options are inputted */
+       if (type_str[0] == '\0' || key[0] == '\0') {
+               printf("Essential options aren't inputted\n\n");
+               show_help();
+               return EINVAL;
+       }
+
+       /* Convert string arguments into the enum value */
+       CONVERT_ARGUMENT(tag_str, sizeof(tag_str), tag_num, tag_table);
+       CONVERT_ARGUMENT(type_str, sizeof(type_str), type_num, type_table);
+       CONVERT_ARGUMENT(runtime_str, sizeof(runtime_str), runtime_num, runtime_table);
+
+       /* Set the runtime environment value */
+       switch (runtime_num) {
+       case RUNTIME_C:
+               ret = setenv(RUNTIME_ENV, "capp", 1);
+               break;
+       case RUNTIME_WEB:
+               ret = setenv(RUNTIME_ENV, "webapp", 1);
+               break;
+       case RUNTIME_DOTNET:
+               ret = setenv(RUNTIME_ENV, "dotnet", 1);
+               break;
+       default:
+               printf("Failed to convert runtime argument\n");
+               return EIO;
+               break;
+       }
+
+       if (ret != SUCCESS) {
+               printf("setenv failed : %m\n");
+               return errno;
+       }
+
+       printf("TAG(%s), TYPE(%s), RUNTIME(%s), KEY(%s), RESULT(",
+                       tag_str, type_str, runtime_str, key);
+
+       /* Call appropriate system-info API and print result */
+       switch (tag_num) {
+       case TAG_PLATFORM:
+               switch (type_num) {
+               case TYPE_BOOL:
+                       ret = system_info_get_platform_bool(key, &val_bool);
+                       if (ret == SYSTEM_INFO_ERROR_NONE)
+                               printf("%d", val_bool);
+                       break;
+               case TYPE_INT:
+                       ret = system_info_get_platform_int(key, &val_int);
+                       if (ret == SYSTEM_INFO_ERROR_NONE)
+                               printf("%d", val_int);
+                       break;
+               case TYPE_DOUBLE:
+                       ret = system_info_get_platform_double(key, &val_double);
+                       if (ret == SYSTEM_INFO_ERROR_NONE)
+                               printf("%lf", val_double);
+                       break;
+               case TYPE_STRING:
+                       ret = system_info_get_platform_string(key, &val_string);
+                       if (ret == SYSTEM_INFO_ERROR_NONE)
+                               printf("%s", val_string);
+                       break;
+               default:
+                       ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+                       break;
+               }
+               break;
+       case TAG_CUSTOM:
+               switch (type_num) {
+               case TYPE_BOOL:
+                       ret = system_info_get_custom_bool(key, &val_bool);
+                       if (ret == SYSTEM_INFO_ERROR_NONE)
+                               printf("%d", val_bool);
+                       break;
+               case TYPE_INT:
+                       ret = system_info_get_custom_int(key, &val_int);
+                       if (ret == SYSTEM_INFO_ERROR_NONE)
+                               printf("%d", val_int);
+                       break;
+               case TYPE_DOUBLE:
+                       ret = system_info_get_custom_double(key, &val_double);
+                       if (ret == SYSTEM_INFO_ERROR_NONE)
+                               printf("%lf", val_double);
+                       break;
+               case TYPE_STRING:
+                       ret = system_info_get_custom_string(key, &val_string);
+                       if (ret == SYSTEM_INFO_ERROR_NONE)
+                               printf("%s", val_string);
+                       break;
+               default:
+                       ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+                       break;
+               }
+               break;
+       default:
+               ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+               break;
+       }
+
+       if (ret != SYSTEM_INFO_ERROR_NONE) {
+               printf("ERROR : %d", ret);
+       }
+
+       printf(")\n");
+
+       return SUCCESS;
+}
diff --git a/test/plugin/CMakeLists.txt b/test/plugin/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..3292cf2
--- /dev/null
@@ -0,0 +1,18 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(SI_PLUGIN "system_info_test_plugin")
+
+SET(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/plugin_test.c)
+
+INCLUDE_DIRECTORIES(include)
+
+ADD_LIBRARY(${SI_PLUGIN} MODULE ${SRCS})
+SET_TARGET_PROPERTIES(${SI_PLUGIN} PROPERTIES COMPILE_FLAGS -DPLUGIN_FIRST)
+ADD_LIBRARY(${SI_PLUGIN}2 MODULE ${SRCS})
+
+SET(TEST_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/system_info_external_plugin_test.sh)
+CONFIGURE_FILE(${TEST_SCRIPT}.in ${TEST_SCRIPT} @ONLY)
+
+INSTALL(TARGETS ${SI_PLUGIN} DESTINATION ${LIB_INSTALL_DIR}/libsystem_info_plugins)
+INSTALL(TARGETS ${SI_PLUGIN}2 DESTINATION ${LIB_INSTALL_DIR}/libsystem_info_plugins)
+
+INSTALL(FILES ${TEST_SCRIPT} DESTINATION bin)
diff --git a/test/plugin/plugin_test.c b/test/plugin/plugin_test.c
new file mode 100644 (file)
index 0000000..5824b80
--- /dev/null
@@ -0,0 +1,62 @@
+#include <string.h>
+#include <system_info_intf.h>
+
+#include "system_info_type.h"
+
+#define VALUES_COUNT (sizeof value_descriptors / sizeof *value_descriptors)
+
+#ifdef PLUGIN_FIRST
+       #define PLUGIN_STRING_VALUE "first_in_lexicographical_order"
+       #define PLUGIN_STRING_KEY ""
+#else
+       #define PLUGIN_STRING_VALUE "second_in_lexicographical_order"
+       #define PLUGIN_STRING_KEY "_custom"
+#endif
+
+const struct entity {
+       const char *key;
+       const char *type;
+       const char *value;
+} value_descriptors[] = {
+       { "sysinfotest_kvs", TYPE_STR, PLUGIN_STRING_VALUE },
+       { "sysinfotest_vks" PLUGIN_STRING_KEY, TYPE_STR, "various key" },
+       { "sysinfotest_ks", TYPE_STR, "plugin" },
+       { "sysinfotest_ki", TYPE_INT, "1" },
+       { "sysinfotest_kd", TYPE_DBL, "2.0" },
+       { "sysinfotest_kb", TYPE_BOOL, "true" }
+};
+
+static int get_value(const char *tag, const char *key, const char *type, char *buf, unsigned int len)
+{
+       if (key && type)
+               for (size_t i = 0; i < VALUES_COUNT; ++i)
+                       if (!strcmp(key, value_descriptors[i].key) && !strcmp(type, value_descriptors[i].type)) {
+                               if (!strncpy(buf, value_descriptors[i].value, len))
+                                       return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+                               return SYSTEM_INFO_ERROR_NONE;
+                       }
+       return SYSTEM_INFO_ERROR_IO_ERROR;
+}
+
+static int get_type(const char *tag, const char *key, char *buf, unsigned int len)
+{
+       if (key)
+               for (size_t i = 0; i < VALUES_COUNT; ++i)
+                       if (!strcmp(key, value_descriptors[i].key)) {
+                               if (!strncpy(buf, value_descriptors[i].type, len))
+                                       return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+                               return SYSTEM_INFO_ERROR_NONE;
+                       }
+       return SYSTEM_INFO_ERROR_IO_ERROR;
+}
+
+const system_info_external_plugin_interface intf = {
+       .get_value_external = get_value,
+       .get_type_external = get_type,
+};
+
+__attribute__ ((visibility ("default")))
+const system_info_external_plugin_interface *system_info_get_external_plugin_interface(void)
+{
+       return &intf;
+}
diff --git a/test/plugin/system_info_external_plugin_test.sh.in b/test/plugin/system_info_external_plugin_test.sh.in
new file mode 100755 (executable)
index 0000000..e5a6839
--- /dev/null
@@ -0,0 +1,136 @@
+#!/bin/bash
+
+function test_key_type_string_cmd() {
+       cmd_result="$(system_info_test -g custom -t string -k sysinfotest_ks)"
+       name="'$FUNCNAME'"
+}
+
+function test_string_not_int_cmd() {
+       cmd_result="$(system_info_test -g custom -t int -k sysinfotest_ks)"
+       name="'$FUNCNAME'"
+}
+
+function test_string_not_double_cmd() {
+       cmd_result="$(system_info_test -g custom -t double -k sysinfotest_ks)"
+       name="'$FUNCNAME'"
+}
+
+function test_string_not_bool_cmd() {
+       cmd_result="$(system_info_test -g custom -t bool -k sysinfotest_ks)"
+       name="'$FUNCNAME'"
+}
+
+function test_key_type_int_cmd() {
+       cmd_result="$(system_info_test -g custom -t int -k sysinfotest_ki)"
+       name="'$FUNCNAME'"
+}
+
+function test_key_type_double_cmd() {
+       cmd_result="$(system_info_test -g custom -t double -k sysinfotest_kd)"
+       name="'$FUNCNAME'"
+}
+
+function test_key_type_bool_cmd() {
+       cmd_result="$(system_info_test -g custom -t bool -k sysinfotest_kb)"
+       name="'$FUNCNAME'"
+}
+
+function test_bool_not_string_cmd() {
+       cmd_result="$(system_info_test -g custom -t string -k sysinfotest_kb)"
+       name="'$FUNCNAME'"
+}
+
+function test_bool_not_int_cmd() {
+       cmd_result="$(system_info_test -g custom -t int -k sysinfotest_kb)"
+       name="'$FUNCNAME'"
+}
+
+function test_bool_not_double_cmd() {
+       cmd_result="$(system_info_test -g custom -t double -k sysinfotest_kb)"
+       name="'$FUNCNAME'"
+}
+
+function test_second_plugin_str_cmd() {
+       cmd_result="$(system_info_test -g custom -t string -k sysinfotest_vks_custom)"
+       name="'$FUNCNAME'"
+}
+
+function test_right_plugin_str_cmd() {
+       cmd_result="$(system_info_test -g custom -t string -k sysinfotest_kvs)"
+       name="'$FUNCNAME'"
+}
+
+function get_cmd_result() {
+       check_result="$(echo $1 | cut -d'(' -f6 | cut -d')' -f1)"
+}
+
+function check_file_exists() {
+       cmd_result="$(test -s $1 && echo 'exists' || echo 'not')"
+       name="'$FUNCNAME' $1"
+}
+
+function check_command_exists() {
+       command_exists="$(type -p system_info_test)"
+}
+
+function check_result() {
+       local test_cmd=$1
+       local expected_result=$2
+
+       $test_cmd
+       get_cmd_result "$cmd_result"
+
+       #check if a variable is a number (formating cmd output)
+       re='^[+-]?[0-9]+([.][0-9]+)?$'
+       if [[ $check_result =~ $re ]] ; then
+               check_result="$(printf '%.2f' $check_result)"
+               if [[ $expected_result =~ $re ]] ; then
+                       expected_result="$(printf '%.2f' $expected_result)"
+               fi
+       fi
+
+       sign='='
+       nsign='!'
+       if [[ $# -ge 3 && $3 == '!' ]]; then
+               nsign=$sign
+               sign=$3
+       fi
+       if [[ $check_result == '' ]]; then
+               check_result='EMPTY_RESULT'
+       fi
+       if [[ ( $check_result != 'EMPTY_RESULT' && ( $sign == '!' && "$check_result" != "$expected_result" ) || ( "$check_result" == "$expected_result" ) ) ]]; then
+               echo -e '\033[32m[' ' OK ' ']\e[0m' "$name:\t" "$sign('$expected_result')"
+       else
+               echo -e '\033[31m[' 'FAIL' ']\e[0m' "$name:\t" "('\033[31m$check_result\e[0m'" "$nsign=" "'\033[32m$expected_result\e[0m')"
+               return_code=1
+       fi
+}
+
+check_command_exists result
+if [ -z "$command_exists" ]; then
+       exit 1
+fi
+
+return_code=0
+
+PLUGIN_FILE='@PLUGIN_DIR@/libsystem_info_plugins/libsystem_info_test_plugin.so'
+check_result "check_file_exists $PLUGIN_FILE" 'exists'
+PLUGIN_FILE='@PLUGIN_DIR@/libsystem_info_plugins/libsystem_info_test_plugin2.so'
+check_result "check_file_exists $PLUGIN_FILE" 'exists'
+
+check_result test_key_type_string_cmd 'plugin'
+check_result test_string_not_int_cmd 'ERROR : -22'
+check_result test_string_not_double_cmd 'ERROR : -22'
+check_result test_string_not_bool_cmd 'ERROR : -22'
+check_result test_key_type_int_cmd '1'
+check_result test_key_type_double_cmd '2.0'
+check_result test_key_type_bool_cmd '1'
+check_result test_bool_not_string_cmd 'ERROR : -22'
+check_result test_bool_not_int_cmd 'ERROR : -22'
+check_result test_bool_not_double_cmd 'ERROR : -22'
+check_result test_second_plugin_str_cmd 'various key'
+check_result test_right_plugin_str_cmd 'first_in_lexicographical_order'
+check_result test_right_plugin_str_cmd 'second_in_lexicographical_order' '!'
+check_result test_right_plugin_str_cmd 'ERROR : -22' '!'
+
+exit $return_code