Add build tests 50/265050/3
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 7 Oct 2021 07:43:06 +0000 (16:43 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 8 Oct 2021 00:54:41 +0000 (09:54 +0900)
When building this package, the tidl-build-tests is also built together.
Before building the codes, the tidl-build-tests generates the codes using tidlc.
The tidl files exist in the tests/buil_tests/tidl directory.
The unit_tests is moved to the tests/unit_tests.

Change-Id: I2816d93468582cdbf1aae3c067667104e3be3d52
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
28 files changed:
CMakeLists.txt
packaging/tidl.spec
tests/CMakeLists.txt [new file with mode: 0644]
tests/build_tests/CMakeLists.txt [new file with mode: 0644]
tests/build_tests/main.cc [new file with mode: 0644]
tests/build_tests/prebuild.sh [new file with mode: 0755]
tests/build_tests/tidl/Buffer.tidl [new file with mode: 0644]
tests/build_tests/tidl/DataPort.tidl [new file with mode: 0644]
tests/build_tests/tidl/Ex.tidl [new file with mode: 0644]
tests/build_tests/tidl/Foo.tidl [new file with mode: 0644]
tests/build_tests/tidl/Message.tidl [new file with mode: 0644]
tests/unit_tests/CMakeLists.txt [moved from unit_tests/CMakeLists.txt with 55% similarity]
tests/unit_tests/attribute_unittest.cc [moved from unit_tests/attribute_unittest.cc with 100% similarity]
tests/unit_tests/block_unittest.cc [moved from unit_tests/block_unittest.cc with 100% similarity]
tests/unit_tests/cs_gen/cs_proxy_gen_unittest.cc [moved from unit_tests/cs_gen/cs_proxy_gen_unittest.cc with 100% similarity]
tests/unit_tests/cs_gen/cs_stub_gen_unittest.cc [moved from unit_tests/cs_gen/cs_stub_gen_unittest.cc with 100% similarity]
tests/unit_tests/declaration_unittest.cc [moved from unit_tests/declaration_unittest.cc with 100% similarity]
tests/unit_tests/document_unittest.cc [moved from unit_tests/document_unittest.cc with 100% similarity]
tests/unit_tests/element_unittest.cc [moved from unit_tests/element_unittest.cc with 100% similarity]
tests/unit_tests/generator_unittest.cc [moved from unit_tests/generator_unittest.cc with 100% similarity]
tests/unit_tests/interface_unittest.cc [moved from unit_tests/interface_unittest.cc with 100% similarity]
tests/unit_tests/main.cc [moved from unit_tests/main.cc with 100% similarity]
tests/unit_tests/parser_unittest.cc [moved from unit_tests/parser_unittest.cc with 100% similarity]
tests/unit_tests/structure_unittest.cc [moved from unit_tests/structure_unittest.cc with 100% similarity]
tests/unit_tests/test.tidl [moved from unit_tests/test.tidl with 100% similarity]
tests/unit_tests/test_error.tidl [moved from unit_tests/test_error.tidl with 100% similarity]
tests/unit_tests/type_unittest.cc [moved from unit_tests/type_unittest.cc with 100% similarity]
tests/unit_tests/unit_tests.sh [moved from unit_tests/unit_tests.sh with 100% similarity]

index fd0ec2d..d698f6e 100644 (file)
@@ -8,13 +8,11 @@ FIND_PACKAGE(FLEX REQUIRED)
 
 IF(NOT DEFINED MINIMUM_BUILD)
 ENABLE_TESTING()
-SET(TIDL_UNIT_TESTS tidl-unit-tests)
+SET(TARGET_TIDL_BUILD_TESTS "tidl-build-tests")
+SET(TIDL_UNIT_TESTS "tidl-unit-tests")
 ADD_TEST(NAME ${TIDL_UNIT_TESTS} COMMAND ${TIDL_UNIT_TESTS} test.tidl test_error.tidl
-               WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unit_tests)
+               WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/unit_tests)
 ENDIF(NOT DEFINED MINIMUM_BUILD)
 
 ADD_SUBDIRECTORY(idlc)
-IF(NOT DEFINED MINIMUM_BUILD)
-ADD_SUBDIRECTORY(unit_tests)
-ADD_DEPENDENCIES(${TIDL_UNIT_TESTS} ${PROJECT_NAME})
-ENDIF(NOT DEFINED MINIMUM_BUILD)
+ADD_SUBDIRECTORY(tests)
index 1c0399d..52dfc3c 100644 (file)
@@ -16,6 +16,9 @@ BuildRequires:  flex
 BuildRequires:  bison
 BuildRequires:  gtest-devel
 BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(rpc-port)
+BuildRequires:  pkgconfig(bundle)
 %if 0%{?gcov:1}
 BuildRequires:  lcov
 %endif
@@ -50,7 +53,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %__make %{?_smp_mflags}
 
 %check
-ctest --output-on-failure %{?_smp_mflags}
+ctest -V %{?_smp_mflags}
 %if 0%{?gcov:1}
 lcov -c --ignore-errors graph --no-external -q -d . -o gcov.info
 genhtml gcov.info
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..84baa03
--- /dev/null
@@ -0,0 +1,7 @@
+IF(NOT DEFINED MINIMUM_BUILD)
+ADD_SUBDIRECTORY(unit_tests)
+ADD_DEPENDENCIES(${TIDL_UNIT_TESTS} ${PROJECT_NAME})
+
+ADD_SUBDIRECTORY(build_tests)
+ADD_DEPENDENCIES(${TARGET_TIDL_BUILD_TESTS} ${PROJECT_NAME})
+ENDIF(NOT DEFINED MINIMUM_BUILD)
diff --git a/tests/build_tests/CMakeLists.txt b/tests/build_tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e086a0f
--- /dev/null
@@ -0,0 +1,49 @@
+SET(TOOL_TIDLC "${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/tidlc")
+SET(TARGET_PREBUILD_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/prebuild.sh")
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(PKGS REQUIRED dlog glib-2.0 rpc-port bundle)
+
+FOREACH(flag ${PKGS_CFLAGS})
+  SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFALGS} -fPIE -Werror")
+SET(CMAKE_EXE_LINKER_FLAGS "-pie -Wl,--as-needed")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TIDL_BUILD_TESTS_SRCS)
+
+SET(TIDL_GEN_SRCS
+  BufferProxy.cc
+  BufferProxyC.c
+  BufferStub.cc
+  BufferStubC.c
+  DataPortProxy.cc
+  DataPortProxyC.c
+  DataPortStub.cc
+  DataPortStubC.c
+  ExProxy.cc
+  ExProxyC.c
+  ExStub.cc
+  ExStubC.c
+  MessageProxy.cc
+  MessageProxyC.c
+  MessageStub.cc
+  MessageStubC.c
+)
+
+ADD_CUSTOM_COMMAND(OUTPUT ${TIDL_GEN_SRCS} PRE_BUILD
+  COMMAND ${TARGET_PREBUILD_SCRIPT} ${TOOL_TIDLC} ${CMAKE_CURRENT_SOURCE_DIR}
+  DEPENDS ${TOOL_TIDLC}
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+ADD_EXECUTABLE(${TARGET_TIDL_BUILD_TESTS}
+  ${TIDL_BUILD_TESTS_SRCS}
+  ${TIDL_GEN_SRCS}
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_TIDL_BUILD_TESTS} ${PKGS_LDFLAGS} "-lpthread")
+
+INSTALL(TARGETS ${TARGET_TIDL_BUILD_TESTS} DESTINATION bin)
diff --git a/tests/build_tests/main.cc b/tests/build_tests/main.cc
new file mode 100644 (file)
index 0000000..f24580c
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2021 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 <iostream>
+
+int main(int argc, char** argv) {
+  std::cout << "TIDL Build Test" << std::endl;
+  return 0;
+}
diff --git a/tests/build_tests/prebuild.sh b/tests/build_tests/prebuild.sh
new file mode 100755 (executable)
index 0000000..16a0d63
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+SCRIPT_FILE=$(readlink -f $0)
+SCRIPT_DIR=$(dirname $SCRIPT_FILE)
+TIDLC=$1
+TARGET_DIR=$2
+
+FILES[0]="Message"
+FILES[1]="Buffer"
+FILES[2]="Ex"
+FILES[3]="DataPort"
+FILES[4]="Foo"
+
+GenerateTIDL() {
+  for index in ${!FILES[*]}; do
+    echo "Generate ${FILES[index]}"
+
+    INPUT="${FILES[index]}.tidl"
+    OUTPUT="${FILES[index]}Stub"
+    ${TIDLC} -s -l C++ -i ${SCRIPT_DIR}/tidl/${INPUT} -o ${TARGET_DIR}/${OUTPUT}
+
+    OUTPUT="${FILES[index]}Proxy"
+    ${TIDLC} -p -l C++ -i ${SCRIPT_DIR}/tidl/${INPUT} -o ${TARGET_DIR}/${OUTPUT}
+
+    OUTPUT="${FILES[index]}StubC"
+    ${TIDLC} -s -n -l C -i ${SCRIPT_DIR}/tidl/${INPUT} -o ${TARGET_DIR}/${OUTPUT}
+
+    OUTPUT="${FILES[index]}ProxyC"
+    ${TIDLC} -p -n -l C -i ${SCRIPT_DIR}/tidl/${INPUT} -o ${TARGET_DIR}/${OUTPUT}
+  done
+}
+
+GenerateTIDL
+
+echo "Done"
diff --git a/tests/build_tests/tidl/Buffer.tidl b/tests/build_tests/tidl/Buffer.tidl
new file mode 100644 (file)
index 0000000..c1525ba
--- /dev/null
@@ -0,0 +1,6 @@
+interface IRemoteBuffer {
+  void BufEvent(array<char> buf) delegate;
+
+  int GetFirst(string id, BufEvent ev, int max_size);
+  int GetNext(string id);
+}
diff --git a/tests/build_tests/tidl/DataPort.tidl b/tests/build_tests/tidl/DataPort.tidl
new file mode 100644 (file)
index 0000000..643d66d
--- /dev/null
@@ -0,0 +1,21 @@
+struct CursorContext {
+  int Handle;
+}
+
+struct Pair {
+  string Key;
+  string Value;
+}
+
+interface DataPort {
+  CursorContext Query(string uri, list<string> projection, string selection, list<string> selectionArgs, string sortOrder);
+  int Insert(string uri, list<Pair> values);
+  int Update(string uri, list<Pair> values, string selection, list<string> selectionArgs);
+  int Delete(string uri, string selection, list<string> selectionArgs);
+
+  bool CursorIsLast(CursorContext cxt);
+  bool CursorMoveToFirst(CursorContext cxt);
+  bool CursorMoveToNext(CursorContext cxt);
+  string CursorGetString(CursorContext cxt, int column);
+  void CursorDispose(CursorContext cxt) async;
+}
diff --git a/tests/build_tests/tidl/Ex.tidl b/tests/build_tests/tidl/Ex.tidl
new file mode 100644 (file)
index 0000000..8a33828
--- /dev/null
@@ -0,0 +1,57 @@
+struct StructTest {
+  int Int;
+  short Short;
+  char Char;
+  bundle Bd;
+  bool Fg;
+  string Str;
+  float Float;
+  double Double;
+  long Long;
+}
+
+struct Student {
+  string name;
+  int num;
+  bundle data;
+  array<char> extra;
+}
+
+struct Class {
+  string name;
+  list<Student> students;
+}
+
+[privilege = "http://tizen.org/privilege/appmanager.launch", privilege = "http://tizen.org/privilege/mediastorage",
+trusted = "true"]
+interface School {
+  void ClassAddedCB(int ret) delegate;
+  int T1(out bool b);
+  int T2(out char c);
+  int T3(out int l);
+  int T4(ref bool b);
+  int T5(ref char c);
+  int T6(ref int l);
+  int T7(out string str);
+  int T8(ref string str);
+  int Test1(out StructTest st);
+  int Test2(StructTest st);
+  int Test3(ref StructTest st);
+  int Test4(out list<StructTest> st);
+  int Test5(list<StructTest> st);
+  int Test6(ref list<StructTest> st);
+
+  /// <summary>
+  /// Add class
+  /// </summary>
+  int AddClass(in Class cls);
+
+  /// <summary>
+  /// Add class async
+  /// </summary>
+  void AddClassAsync(Class cls, ClassAddedCB cb) async;
+
+  int GetStudent(in string c_name, in string s_name, out Student student);
+  int SetAllIds(list<list<int>> nums);
+  int SetExtra(string s_name, array<char> extra);
+}
diff --git a/tests/build_tests/tidl/Foo.tidl b/tests/build_tests/tidl/Foo.tidl
new file mode 100644 (file)
index 0000000..03ac041
--- /dev/null
@@ -0,0 +1,9 @@
+struct Foo {
+  int Age;
+  string Name;
+}
+
+interface Runnable {
+  int Run(Foo foo);
+  list<string> GetNames();
+}
diff --git a/tests/build_tests/tidl/Message.tidl b/tests/build_tests/tidl/Message.tidl
new file mode 100644 (file)
index 0000000..28f45ad
--- /dev/null
@@ -0,0 +1,7 @@
+interface Message {
+  void NotifyCB(string sender, string msg) delegate;
+
+  int Register(string name, NotifyCB cb);
+  void Unregister() async;
+  int Send(string msg);
+}
similarity index 55%
rename from unit_tests/CMakeLists.txt
rename to tests/unit_tests/CMakeLists.txt
index 96849aa..9390822 100644 (file)
@@ -14,27 +14,29 @@ INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS})
 LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS})
 
 SET(TIDLC_SOURCES
-       ${CMAKE_SOURCE_DIR}/idlc/ast/document.cc
-       ${CMAKE_SOURCE_DIR}/idlc/ast/declaration.cc
-       ${CMAKE_SOURCE_DIR}/idlc/ast/interface.cc
-       ${CMAKE_SOURCE_DIR}/idlc/ast/type.cc
-       ${CMAKE_SOURCE_DIR}/idlc/ast/parameter.cc
-       ${CMAKE_SOURCE_DIR}/idlc/ast/element.cc
-       ${CMAKE_SOURCE_DIR}/idlc/ast/structure.cc
-       ${CMAKE_SOURCE_DIR}/idlc/ast/block.cc
-       ${CMAKE_SOURCE_DIR}/idlc/gen/generator.cc
-       ${CMAKE_SOURCE_DIR}/idlc/ast/parser.cc
-       ${CMAKE_SOURCE_DIR}/idlc/ast/attribute.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/document.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/declaration.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/interface.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/type.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/parameter.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/element.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/structure.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/block.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/gen/generator.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/parser.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/attribute.cc
        )
 
 ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"")
 
 AUX_SOURCE_DIRECTORY(. UNIT_TESTS_SOURCES)
 AUX_SOURCE_DIRECTORY(cs_gen CS_GEN_UNIT_TESTS_SOURCES)
-AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/idlc/gen CS_GEN_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/gen CS_GEN_SOURCES)
 
-FLEX_TARGET(TIDLC ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc.ll ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc_l.cpp)
-BISON_TARGET(TIDLC ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc.yy ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc_y.cpp)
+FLEX_TARGET(TIDLC ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/tidlc.ll
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/tidlc_l.cpp)
+BISON_TARGET(TIDLC ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/tidlc.yy
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/tidlc_y.cpp)
 
 ADD_EXECUTABLE(${TIDL_UNIT_TESTS}
        ${BISON_TIDLC_OUTPUTS}
similarity index 100%
rename from unit_tests/main.cc
rename to tests/unit_tests/main.cc