From 19564cb4f77660cdb2f980ca619d4b979b9fe342 Mon Sep 17 00:00:00 2001 From: Boyuan Yang Date: Mon, 27 Nov 2023 22:46:29 -0500 Subject: New upstream version 0.19.0 --- tests/fuzzer/fuzzer_temp_file.h | 45 +++++++++++++++++++++++++++++++++++++-- tests/fuzzer/obu_parser_fuzzer.cc | 5 +++++ tests/libgav1_tests.cmake | 43 ++++++++++++++++++------------------- 3 files changed, 69 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/fuzzer/fuzzer_temp_file.h b/tests/fuzzer/fuzzer_temp_file.h index 5d12bbe..ed8f51c 100644 --- a/tests/fuzzer/fuzzer_temp_file.h +++ b/tests/fuzzer/fuzzer_temp_file.h @@ -25,12 +25,52 @@ #include #include #include +#ifdef _WIN32 +#include +#include + +#define strdup _strdup +#define unlink _unlink +#else #include +#endif // _WIN32 // Pure-C interface for creating and cleaning up temporary files. static char* fuzzer_get_tmpfile_with_suffix(const uint8_t* data, size_t size, const char* suffix) { +#ifdef _WIN32 + // GetTempPathA generates '\
.TMP'.
+  (void)suffix;  // NOLINT (this could be a C compilation unit)
+  char temp_path[MAX_PATH];
+  const DWORD ret = GetTempPathA(MAX_PATH, temp_path);
+  if (ret == 0 || ret > MAX_PATH) {
+    fprintf(stderr, "Error getting temporary directory name: %lu\n",
+            GetLastError());
+    abort();
+  }
+  char* filename_buffer =
+      (char*)malloc(MAX_PATH);  // NOLINT (this could be a C compilation unit)
+  if (!filename_buffer) {
+    perror("Failed to allocate file name buffer.");
+    abort();
+  }
+  if (GetTempFileNameA(temp_path, "ftf", /*uUnique=*/0, filename_buffer) == 0) {
+    fprintf(stderr, "Error getting temporary file name: %lu\n", GetLastError());
+    abort();
+  }
+#if defined(_MSC_VER) || defined(MINGW_HAS_SECURE_API)
+  FILE* file;
+  const errno_t err = fopen_s(&file, filename_buffer, "wb");
+  if (err != 0) file = NULL;  // NOLINT (this could be a C compilation unit)
+#else
+  FILE* file = fopen(filename_buffer, "wb");
+#endif
+  if (!file) {
+    perror("Failed to open file.");
+    abort();
+  }
+#else  // !_WIN32
   if (suffix == NULL) {  // NOLINT (this could be a C compilation unit)
     suffix = "";
   }
@@ -55,7 +95,7 @@ static char* fuzzer_get_tmpfile_with_suffix(const uint8_t* data, size_t size,
   }
 
   if (snprintf(filename_buffer, buffer_sz, "%s%s", leading_temp_path, suffix) >=
-      buffer_sz) {
+      (int)buffer_sz) {  // NOLINT (this could be a C compilation unit)
     perror("File name buffer too short.");
     abort();
   }
@@ -71,9 +111,10 @@ static char* fuzzer_get_tmpfile_with_suffix(const uint8_t* data, size_t size,
     close(file_descriptor);
     abort();
   }
+#endif  // _WIN32
   const size_t bytes_written = fwrite(data, sizeof(uint8_t), size, file);
   if (bytes_written < size) {
-    close(file_descriptor);
+    fclose(file);
     fprintf(stderr, "Failed to write all bytes to file (%zu out of %zu)",
             bytes_written, size);
     abort();
diff --git a/tests/fuzzer/obu_parser_fuzzer.cc b/tests/fuzzer/obu_parser_fuzzer.cc
index 634a802..f71ca17 100644
--- a/tests/fuzzer/obu_parser_fuzzer.cc
+++ b/tests/fuzzer/obu_parser_fuzzer.cc
@@ -41,6 +41,11 @@ constexpr size_t kMaxDataSize = 200 * 1024;
 #endif
 
 inline void ParseObu(const uint8_t* const data, size_t size) {
+  size_t av1c_size;
+  const std::unique_ptr av1c_box =
+      libgav1::ObuParser::GetAV1CodecConfigurationBox(data, size, &av1c_size);
+  static_cast(av1c_box);
+
   libgav1::InternalFrameBufferList buffer_list;
   libgav1::BufferPool buffer_pool(libgav1::OnInternalFrameBufferSizeChanged,
                                   libgav1::GetInternalFrameBuffer,
diff --git a/tests/libgav1_tests.cmake b/tests/libgav1_tests.cmake
index c759d4f..95f6361 100644
--- a/tests/libgav1_tests.cmake
+++ b/tests/libgav1_tests.cmake
@@ -28,7 +28,7 @@ if(NOT LIBGAV1_ENABLE_TESTS OR NOT EXISTS "${libgav1_googletest}")
       "GoogleTest not found, setting LIBGAV1_ENABLE_TESTS to false.\n"
       "To enable tests download the GoogleTest repository to"
       " third_party/googletest:\n\n  git \\\n    -C ${libgav1_root} \\\n"
-      "    clone \\\n"
+      "    clone -b release-1.12.1 --depth 1 \\\n"
       "    https://github.com/google/googletest.git third_party/googletest\n")
     set(LIBGAV1_ENABLE_TESTS FALSE CACHE BOOL "Enables tests." FORCE)
   endif()
@@ -86,13 +86,17 @@ list(APPEND libgav1_common_avx2_test_sources
             "${libgav1_source}/dsp/x86/common_avx2.h"
             "${libgav1_source}/dsp/x86/common_avx2.inc"
             "${libgav1_source}/dsp/x86/common_avx2_test.cc"
+            "${libgav1_source}/dsp/x86/common_avx2_test.h"
             "${libgav1_source}/dsp/x86/common_sse4.inc")
+list(APPEND libgav1_common_dsp_test_sources
+            "${libgav1_source}/dsp/common_dsp_test.cc")
 list(APPEND libgav1_common_neon_test_sources
             "${libgav1_source}/dsp/arm/common_neon_test.cc")
 list(APPEND libgav1_common_sse4_test_sources
             "${libgav1_source}/dsp/x86/common_sse4.h"
             "${libgav1_source}/dsp/x86/common_sse4.inc"
-            "${libgav1_source}/dsp/x86/common_sse4_test.cc")
+            "${libgav1_source}/dsp/x86/common_sse4_test.cc"
+            "${libgav1_source}/dsp/x86/common_sse4_test.h")
 list(APPEND libgav1_convolve_test_sources
             "${libgav1_source}/dsp/convolve_test.cc")
 list(APPEND libgav1_cpu_test_sources "${libgav1_source}/utils/cpu_test.cc")
@@ -275,19 +279,29 @@ macro(libgav1_add_tests_targets)
                          libgav1_gtest_main)
 
   if(libgav1_have_avx2)
+    list(APPEND libgav1_common_dsp_test_sources
+                ${libgav1_common_avx2_test_sources})
+  endif()
+  if(libgav1_have_sse4)
+    list(APPEND libgav1_common_dsp_test_sources
+                ${libgav1_common_sse4_test_sources})
+  endif()
+  if(libgav1_have_avx2 OR libgav1_have_sse4)
     libgav1_add_executable(TEST
                            NAME
-                           common_avx2_test
+                           common_dsp_test
                            SOURCES
-                           ${libgav1_common_avx2_test_sources}
+                           ${libgav1_common_dsp_test_sources}
                            DEFINES
                            ${libgav1_defines}
                            INCLUDES
                            ${libgav1_test_include_paths}
+                           OBJLIB_DEPS
+                           libgav1_utils
                            LIB_DEPS
                            ${libgav1_common_test_absl_deps}
-                           libgav1_gtest
-                           libgav1_gtest_main)
+                           libgav1_gtest_main
+                           libgav1_gtest)
   endif()
 
   if(libgav1_have_neon)
@@ -302,22 +316,7 @@ macro(libgav1_add_tests_targets)
                            ${libgav1_test_include_paths}
                            OBJLIB_DEPS
                            libgav1_tests_block_utils
-                           LIB_DEPS
-                           ${libgav1_common_test_absl_deps}
-                           libgav1_gtest
-                           libgav1_gtest_main)
-  endif()
-
-  if(libgav1_have_sse4)
-    libgav1_add_executable(TEST
-                           NAME
-                           common_sse4_test
-                           SOURCES
-                           ${libgav1_common_sse4_test_sources}
-                           DEFINES
-                           ${libgav1_defines}
-                           INCLUDES
-                           ${libgav1_test_include_paths}
+                           libgav1_utils
                            LIB_DEPS
                            ${libgav1_common_test_absl_deps}
                            libgav1_gtest
-- 
cgit v1.2.3