]> granicus.if.org Git - check/commitdiff
Add tests for modifying maximal message size.
authorOren Ben-Kiki <oren@ben-kiki.org>
Sun, 27 Aug 2017 20:49:18 +0000 (23:49 +0300)
committerOren Ben-Kiki <oren@ben-kiki.org>
Sun, 27 Aug 2017 20:49:18 +0000 (23:49 +0300)
CMakeLists.txt
tests/CMakeLists.txt
tests/Makefile.am
tests/check_env_max_msg_size.c [new file with mode: 0644]
tests/check_set_max_msg_size.c [new file with mode: 0644]
tests/test_env_max_msg_size.sh [new file with mode: 0755]
tests/test_set_max_msg_size.sh [new file with mode: 0755]

index 90c5323997886bbcc5ac622fc8330ef1a189ffe3..453b9ee18d4b6949a78a12e483d5ea1b648fc969 100644 (file)
@@ -361,5 +361,11 @@ if (CHECK_ENABLE_TESTS)
     add_test(NAME test_check_nofork_teardown.sh
       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
       COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_check_nofork_teardown.sh)
+    add_test(NAME test_env_max_msg_size.sh
+      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
+      COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_env_max_msg_size.sh)
+    add_test(NAME test_set_max_msg_size.sh
+      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
+      COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_set_max_msg_size.sh)
   endif(UNIX OR MINGW OR MSYS)
 endif()
index 27ad1bf653a95a03dfd5f4ae4986526c926b310f..a37c067e33ba0b0de2b5dbfaa39df4b862025fe9 100644 (file)
@@ -85,3 +85,11 @@ target_link_libraries(check_nofork check compat)
 set(CHECK_NOFORK_TEARDOWN_SOURCES check_nofork_teardown.c)
 add_executable(check_nofork_teardown ${CHECK_NOFORK_TEARDOWN_SOURCES})
 target_link_libraries(check_nofork_teardown check compat)
+
+set(CHECK_ENV_MAX_MSG_SIZE_SOURCES check_env_max_msg_size.c)
+add_executable(check_env_max_msg_size ${CHECK_ENV_MAX_MSG_SIZE_SOURCES})
+target_link_libraries(check_env_max_msg_size check compat)
+
+set(CHECK_SET_MAX_MSG_SIZE_SOURCES check_set_max_msg_size.c)
+add_executable(check_set_max_msg_size ${CHECK_SET_MAX_MSG_SIZE_SOURCES})
+target_link_libraries(check_set_max_msg_size check compat)
index 06bf29dd72d9e4fb09f4673ffb301848fb36cecb..6bc2e807aef70e2959c1a99d5b8f9f50396d8164 100644 (file)
@@ -8,6 +8,8 @@ TESTS = \
        test_check_nofork_teardown.sh    \
        test_xml_output.sh      \
        test_log_output.sh      \
+       test_env_max_msg_size.sh        \
+       test_set_max_msg_size.sh        \
        test_tap_output.sh
 
 # check_thread_stress is kind of slow.
@@ -26,9 +28,11 @@ noinst_PROGRAMS =            \
        check_nofork            \
        check_nofork_teardown \
        check_mem_leaks         \
+       check_env_max_msg_size  \
+       check_set_max_msg_size  \
        ex_output
 
-EXTRA_DIST = test_output.sh test_check_nofork.sh test_check_nofork_teardown.sh test_log_output.sh test_vars.in test_xml_output.sh test_tap_output.sh test_mem_leaks.sh test_output_strings
+EXTRA_DIST = test_output.sh test_check_nofork.sh test_check_nofork_teardown.sh test_log_output.sh test_vars.in test_xml_output.sh test_tap_output.sh test_mem_leaks.sh test_output_strings test_env_max_msg_size.sh test_set_max_msg_size.sh
 
 if NO_TIMEOUT_TESTS
 check_check_CFLAGS = -DTIMEOUT_TESTS_ENABLED=0
@@ -75,6 +79,14 @@ check_mem_leaks_SOURCES =    \
 check_mem_leaks_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
 check_mem_leaks_CFLAGS = -DTIMEOUT_TESTS_ENABLED=0 -DMEMORY_LEAKING_TESTS_ENABLED=0
 
+check_env_max_msg_size_SOURCES =       \
+       check_env_max_msg_size.c
+check_env_max_msg_size_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
+
+check_set_max_msg_size_SOURCES =       \
+       check_set_max_msg_size.c
+check_set_max_msg_size_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
+
 check_stress_SOURCES = check_stress.c
 check_stress_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
 
diff --git a/tests/check_env_max_msg_size.c b/tests/check_env_max_msg_size.c
new file mode 100644 (file)
index 0000000..8cbb142
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Check: a unit test framework for C
+ * Copyright (C) 2001, 2002 Arien Malec
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+/**
+ * The purpose of this test is to be used by valgrind to check for
+ * memory leaks. Each public API that check exports is used at
+ * least once. Tests which use non-public API, or leak intentionally,
+ * are not included here.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <check.h>
+#include "config.h"
+#include "check_check.h"
+
+START_TEST(test_env_max_msg_size)
+{
+  ck_abort_msg("40 characters of an assertion message...");
+}
+END_TEST
+
+
+static Suite *make_env_max_msg_size_suite(void)
+{
+  Suite *s = suite_create("Check Env Max Msg Size");
+
+  TCase *tc_env_max_msg_size = tcase_create("Test Env Max Msg Size");
+
+  suite_add_tcase (s, tc_env_max_msg_size);
+
+  tcase_add_test (tc_env_max_msg_size, test_env_max_msg_size);
+
+  return s;
+}
+
+int main (void)
+{
+    int n;
+    SRunner *sr;
+
+    /*
+     * Run the test suite. This is intended to trigger the "Message is too long" error.
+     * Actual success/failure is determined by examining the output.
+     */
+    check_set_max_msg_size(4096); // This will have no effect due to the environment variable.
+    sr = srunner_create(make_env_max_msg_size_suite());
+    srunner_run_all(sr, CK_NORMAL);
+    srunner_free(sr);
+    return EXIT_SUCCESS;
+}
+
diff --git a/tests/check_set_max_msg_size.c b/tests/check_set_max_msg_size.c
new file mode 100644 (file)
index 0000000..91dde70
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Check: a unit test framework for C
+ * Copyright (C) 2001, 2002 Arien Malec
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+/**
+ * The purpose of this test is to be used by valgrind to check for
+ * memory leaks. Each public API that check exports is used at
+ * least once. Tests which use non-public API, or leak intentionally,
+ * are not included here.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <check.h>
+#include "config.h"
+#include "check_check.h"
+
+START_TEST(test_set_max_msg_size)
+{
+  ck_abort_msg("40 characters of an assertion message...");
+}
+END_TEST
+
+
+static Suite *make_set_max_msg_size_suite(void)
+{
+  Suite *s = suite_create("Check Set Max Msg Size");
+
+  TCase *tc_set_max_msg_size = tcase_create("Test Set Max Msg Size");
+
+  suite_add_tcase (s, tc_set_max_msg_size);
+
+  tcase_add_test (tc_set_max_msg_size, test_set_max_msg_size);
+
+  return s;
+}
+
+int main (void)
+{
+    int n;
+    SRunner *sr;
+
+    /*
+     * Run the test suite. This is intended to trigger the "Message is too long" error.
+     * Actual success/failure is determined by examining the output.
+     */
+    check_set_max_msg_size(32); // This will have an effect due to no environment variable.
+    sr = srunner_create(make_set_max_msg_size_suite());
+    srunner_run_all(sr, CK_NORMAL);
+    srunner_free(sr);
+    return EXIT_SUCCESS;
+}
+
diff --git a/tests/test_env_max_msg_size.sh b/tests/test_env_max_msg_size.sh
new file mode 100755 (executable)
index 0000000..6990cdd
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/env sh
+
+UNIT_TEST=./check_env_max_msg_size
+MAX_MESSAGE_LOG_FILE=${UNIT_TEST}.output
+TOO_LONG_MESSAGE="Message string too long"
+
+# This test reduces the maximal message size using the environment variable,
+# so that the assertion message becomes too long.
+
+rm -f ${MAX_MESSAGE_LOG_FILE}
+export CK_MAX_MSG_SIZE=32
+${UNIT_TEST} 2>&1 | tee ${MAX_MESSAGE_LOG_FILE}
+
+NUM_TOO_LONG_MESSAGES=$(grep "${TOO_LONG_MESSAGE}" ${MAX_MESSAGE_LOG_FILE} | wc -l)
+
+if test ${NUM_TOO_LONG_MESSAGES} -gt 0; then
+    echo "Maximal message size was reduced."
+    exit 0
+else
+    echo "ERROR: Maximal message size was not reduced."
+    exit 1
+fi
diff --git a/tests/test_set_max_msg_size.sh b/tests/test_set_max_msg_size.sh
new file mode 100755 (executable)
index 0000000..932ce68
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/env sh
+
+UNIT_TEST=./check_set_max_msg_size
+MAX_MESSAGE_LOG_FILE=${UNIT_TEST}.output
+TOO_LONG_MESSAGE="Message string too long"
+
+# This test reduces the maximal message size using the provided function,
+# so that the assertion message becomes too long.
+
+rm -f ${MAX_MESSAGE_LOG_FILE}
+
+${UNIT_TEST} 2>&1 | tee ${MAX_MESSAGE_LOG_FILE}
+
+NUM_TOO_LONG_MESSAGES=$(grep "${TOO_LONG_MESSAGE}" ${MAX_MESSAGE_LOG_FILE} | wc -l)
+
+if test ${NUM_TOO_LONG_MESSAGES} -gt 0; then
+    echo "Maximal message size was reduced."
+    exit 0
+else
+    echo "ERROR: Maximal message size was not reduced."
+    exit 1
+fi