Bladeren bron

testautomation: avoid format related warnings by using a few pragma's

ci: enable -Werror to a few platforms
Anonymous Maarten 2 jaren geleden
bovenliggende
commit
274ec02581
5 gewijzigde bestanden met toevoegingen van 177 en 2 verwijderingen
  1. 19 0
      test/CMakeLists.txt
  2. 84 0
      test/configure
  3. 36 0
      test/configure.ac
  4. 10 1
      test/testautomation_platform.c
  5. 28 1
      test/testautomation_stdlib.c

+ 19 - 0
test/CMakeLists.txt

@@ -160,6 +160,25 @@ add_executable(controllermap controllermap.c testutils.c)
 add_executable(testvulkan testvulkan.c)
 add_executable(testoffscreen testoffscreen.c)
 
+cmake_push_check_state(RESET)
+
+check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
+if(HAVE_WFORMAT_OVERFLOW)
+    target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_OVERFLOW)
+endif()
+
+check_c_compiler_flag(-Wformat HAVE_WFORMAT)
+if(HAVE_WFORMAT)
+    target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT)
+endif()
+
+check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS)
+if(HAVE_WFORMAT_EXTRA_ARGS)
+    target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS)
+endif()
+
+cmake_pop_check_state()
+
 SET(ALL_TESTS
     checkkeys
     checkkeysthreads

+ 84 - 0
test/configure

@@ -4664,6 +4664,90 @@ if test x$have_opengl = xyes; then
     OPENGL_TARGETS="TARGETS"
 fi
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -Wformat" >&5
+printf %s "checking for GCC -Wformat... " >&6; }
+have_wformat=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int x = 0;
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+  have_wformat=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_wformat" >&5
+printf "%s\n" "$have_wformat" >&6; }
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat = xyes; then
+    CFLAGS="$CFLAGS -DHAVE_WFORMAT"
+fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -Wformat-overflow" >&5
+printf %s "checking for GCC -Wformat-overflow... " >&6; }
+have_wformat_overflow=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat-overflow"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int x = 0;
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+  have_wformat_overflow=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_wformat_overflow" >&5
+printf "%s\n" "$have_wformat_overflow" >&6; }
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat_overflow = xyes; then
+    CFLAGS="$CFLAGS -DHAVE_WFORMAT_OVERFLOW"
+fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -Wformat-extra-args" >&5
+printf %s "checking for GCC -Wformat-extra-args... " >&6; }
+have_wformat_extra_args=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat-extra-args"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int x = 0;
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+  have_wformat_extra_args=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_wformat_extra_args" >&5
+printf "%s\n" "$have_wformat_extra_args" >&6; }
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat_extra_args = xyes; then
+    CFLAGS="$CFLAGS -DHAVE_WFORMAT_EXTRA_ARGS"
+fi
+
 # Check whether --enable-werror was given.
 if test ${enable_werror+y}
 then :

+ 36 - 0
test/configure.ac

@@ -184,6 +184,42 @@ if test x$have_opengl = xyes; then
     OPENGL_TARGETS="TARGETS"
 fi
 
+AC_MSG_CHECKING(for GCC -Wformat)
+have_wformat=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
+    [have_wformat=yes], [])
+AC_MSG_RESULT($have_wformat)
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat = xyes; then
+    CFLAGS="$CFLAGS -DHAVE_WFORMAT"
+fi
+
+AC_MSG_CHECKING(for GCC -Wformat-overflow)
+have_wformat_overflow=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat-overflow"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
+    [have_wformat_overflow=yes], [])
+AC_MSG_RESULT($have_wformat_overflow)
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat_overflow = xyes; then
+    CFLAGS="$CFLAGS -DHAVE_WFORMAT_OVERFLOW"
+fi
+
+AC_MSG_CHECKING(for GCC -Wformat-extra-args)
+have_wformat_extra_args=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat-extra-args"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
+    [have_wformat_extra_args=yes], [])
+AC_MSG_RESULT($have_wformat_extra_args)
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat_extra_args = xyes; then
+    CFLAGS="$CFLAGS -DHAVE_WFORMAT_EXTRA_ARGS"
+fi
+
 AC_ARG_ENABLE(werror,
 [AS_HELP_STRING([--enable-werror], [treat warnings as errors [default=no]])],
               enable_werror=$enableval, enable_werror=no)

+ 10 - 1
test/testautomation_platform.c

@@ -376,6 +376,11 @@ int platform_testSetErrorEmptyInput(void *arg)
    return TEST_COMPLETED;
 }
 
+#if defined(HAVE_WFORMAT_OVERFLOW)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-overflow"
+#endif
+
 /* !
  * \brief Tests SDL_SetError with invalid input
  * \sa
@@ -451,7 +456,7 @@ int platform_testSetErrorInvalidInput(void *arg)
              probeError,
              lastError);
    }
-   
+
    /* Clean up */
    SDL_ClearError();
    SDLTest_AssertPass("SDL_ClearError()");
@@ -459,6 +464,10 @@ int platform_testSetErrorInvalidInput(void *arg)
    return TEST_COMPLETED;
 }
 
+#if defined(HAVE_WFORMAT_OVERFLOW)
+#pragma GCC diagnostic pop
+#endif
+
 /* !
  * \brief Tests SDL_GetPowerInfo
  * \sa

+ 28 - 1
test/testautomation_stdlib.c

@@ -7,7 +7,6 @@
 #include "SDL.h"
 #include "SDL_test.h"
 
-
 /* Test case functions */
 
 /**
@@ -36,6 +35,16 @@ stdlib_strlcpy(void *arg)
   return TEST_COMPLETED;
 }
 
+#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic push
+#if defined(HAVE_WFORMAT)
+#pragma GCC diagnostic ignored "-Wformat"
+#endif
+#if defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic ignored "-Wformat-extra-args"
+#endif
+#endif
+
 /**
  * @brief Call to SDL_snprintf
  */
@@ -159,6 +168,10 @@ stdlib_snprintf(void *arg)
   return TEST_COMPLETED;
 }
 
+#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic pop
+#endif
+
 /**
  * @brief Call to SDL_getenv and SDL_setenv
  */
@@ -293,6 +306,16 @@ stdlib_getsetenv(void *arg)
   return TEST_COMPLETED;
 }
 
+#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic push
+#if defined(HAVE_WFORMAT)
+#pragma GCC diagnostic ignored "-Wformat"
+#endif
+#if defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic ignored "-Wformat-extra-args"
+#endif
+#endif
+
 /**
  * @brief Call to SDL_sscanf
  */
@@ -375,6 +398,10 @@ stdlib_sscanf(void *arg)
   return TEST_COMPLETED;
 }
 
+#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic pop
+#endif
+
 #if defined(_WIN64)
 # define SIZE_FORMAT "I64u"
 #elif defined(__WIN32__)