mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-20 04:44:05 +00:00
rewritten all remaining tests without cppunit
This commit is contained in:
@@ -4,18 +4,19 @@
|
||||
#include "config_win32.h"
|
||||
#endif
|
||||
|
||||
#if defined HAVE_CPPUNIT && defined HAVE_GPUJPEG
|
||||
extern "C" bool gpujpeg_test_simple();
|
||||
|
||||
#if defined HAVE_GPUJPEG
|
||||
|
||||
#include <algorithm>
|
||||
#include <cppunit/config/SourcePrefix.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gpujpeg_test.h"
|
||||
#include "host.h"
|
||||
#include "module.h"
|
||||
#include "unit_common.h"
|
||||
#include "video.h"
|
||||
#include "video_compress.h"
|
||||
#include "video_decompress.h"
|
||||
@@ -27,11 +28,24 @@ using std::shared_ptr;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
|
||||
// Registers the fixture into the 'registry'
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( gpujpeg_test );
|
||||
struct compress_state;
|
||||
struct state_decompress;
|
||||
|
||||
void
|
||||
gpujpeg_test::setUp()
|
||||
static bool no_gpu = false;
|
||||
static compress_state *compress{nullptr};
|
||||
static state_decompress *decompress{nullptr};
|
||||
|
||||
static void gpujpeg_test_teardown()
|
||||
{
|
||||
module_done(CAST_MODULE(compress));
|
||||
if (decompress != nullptr) {
|
||||
decompress_done(decompress);
|
||||
}
|
||||
}
|
||||
|
||||
static pthread_once_t set_up = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void gpujpeg_test_setup()
|
||||
{
|
||||
struct compress_state *compression;
|
||||
int ret = compress_init(nullptr, "GPUJPEG:check", &compression);
|
||||
@@ -41,63 +55,59 @@ gpujpeg_test::setUp()
|
||||
}
|
||||
} else {
|
||||
clog << "Either GPUJPEG not compiled in or no CUDA-capable devices found - skipping GPUJPEG tests.\n";
|
||||
m_skip = true;
|
||||
no_gpu = true;
|
||||
return;
|
||||
}
|
||||
|
||||
ret = compress_init(nullptr, "GPUJPEG", &m_compress);
|
||||
CPPUNIT_ASSERT_MESSAGE("Compression initialization failed", ret >= 0);
|
||||
ret = compress_init(nullptr, "GPUJPEG", &compress);
|
||||
assert(ret >= 0 && "Compression initialization failed");
|
||||
|
||||
commandline_params["decompress"] = "gpujpeg";
|
||||
atexit(gpujpeg_test_teardown);
|
||||
}
|
||||
|
||||
void
|
||||
gpujpeg_test::tearDown()
|
||||
{
|
||||
module_done(CAST_MODULE(m_compress));
|
||||
if (m_decompress != nullptr) {
|
||||
decompress_done(m_decompress);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gpujpeg_test::test_simple()
|
||||
bool gpujpeg_test_simple()
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
|
||||
if (m_skip) {
|
||||
return;
|
||||
pthread_once(&set_up, gpujpeg_test_setup);
|
||||
if (no_gpu) {
|
||||
return true;
|
||||
}
|
||||
|
||||
struct video_desc desc{1920, 1080, RGB, 1, PROGRESSIVE, 1};
|
||||
auto in = shared_ptr<video_frame>(vf_alloc_desc_data(desc), vf_free);
|
||||
memset(in->tiles[0].data, 127, in->tiles[0].data_len); /// @todo use some more reasonable stuff
|
||||
|
||||
compress_frame(m_compress, in);
|
||||
auto compressed = compress_pop(m_compress);
|
||||
CPPUNIT_ASSERT_MESSAGE("Compression failed", compressed);
|
||||
compress_frame(compress, in);
|
||||
auto compressed = compress_pop(compress);
|
||||
ASSERT_MESSAGE("Compression failed", compressed);
|
||||
|
||||
vector<unsigned char> decompressed(in->tiles[0].data_len);
|
||||
auto comp_desc = desc;
|
||||
comp_desc.color_spec = JPEG;
|
||||
if (bool ret = decompress_init_multi(JPEG, pixfmt_desc{}, RGB, &m_decompress, 1)) {
|
||||
CPPUNIT_ASSERT_MESSAGE("Decompression init failed", ret);
|
||||
if (bool ret = decompress_init_multi(JPEG, pixfmt_desc{}, RGB, &decompress, 1)) {
|
||||
ASSERT_MESSAGE("Decompression init failed", ret);
|
||||
}
|
||||
auto ret = decompress_reconfigure(m_decompress, comp_desc, 0, 8, 16, vc_get_linesize(desc.width, desc.color_spec), desc.color_spec);
|
||||
CPPUNIT_ASSERT_MESSAGE("Decompression reconfiguration failed", ret == TRUE);
|
||||
auto status = decompress_frame(m_decompress,
|
||||
auto ret = decompress_reconfigure(decompress, comp_desc, 0, 8, 16, vc_get_linesize(desc.width, desc.color_spec), desc.color_spec);
|
||||
ASSERT_MESSAGE("Decompression reconfiguration failed", ret == TRUE);
|
||||
auto status = decompress_frame(decompress,
|
||||
decompressed.data(),
|
||||
reinterpret_cast<unsigned char *>(compressed->tiles[0].data),
|
||||
compressed->tiles[0].data_len,
|
||||
0,
|
||||
nullptr,
|
||||
nullptr);
|
||||
CPPUNIT_ASSERT_MESSAGE("Decompression failed", status == DECODER_GOT_FRAME);
|
||||
ASSERT_MESSAGE("Decompression failed", status == DECODER_GOT_FRAME);
|
||||
|
||||
int i = 0;
|
||||
int max_diff = 0;
|
||||
for_each(decompressed.begin(), decompressed.end(), [&](unsigned char &x) {max_diff = max(abs(x - (unsigned char) in->tiles[0].data[i++]), max_diff);});
|
||||
CPPUNIT_ASSERT_MESSAGE("Maximal allowed difference 1, found "s + to_string(max_diff), max_diff <= 1);
|
||||
ASSERT_MESSAGE("Maximal allowed difference 1, found "s + to_string(max_diff), max_diff <= 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // defined HAVE_CPPUNIT && defined HAVE_GPUJPEG
|
||||
#else
|
||||
bool gpujpeg_test_simple()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif // defined HAVE_GPUJPEG
|
||||
|
||||
Reference in New Issue
Block a user