From c7fcc3ef4b51f78f224b2c388b7178aa3b65c0d4 Mon Sep 17 00:00:00 2001 From: castano Date: Thu, 14 Feb 2008 09:21:57 +0000 Subject: [PATCH] Improve stress test to detect errors in the output. --- src/nvtt/tests/stress.cpp | 75 +++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/src/nvtt/tests/stress.cpp b/src/nvtt/tests/stress.cpp index 4a919ba..c79434a 100644 --- a/src/nvtt/tests/stress.cpp +++ b/src/nvtt/tests/stress.cpp @@ -24,9 +24,64 @@ #include #include // printf -#include // rand? +#include // rand #include // clock +#include // memcpy, memcmp +#include +#define FRAME_COUNT 1000 + +#define WIDTH 1024 +#define HEIGHT 1024 +#define INPUT_SIZE (WIDTH*HEIGHT) +#define OUTPUT_SIZE (WIDTH*HEIGHT/16*2) + +static int s_input[INPUT_SIZE]; +static int s_reference[OUTPUT_SIZE]; +static int s_output[OUTPUT_SIZE]; +static int s_frame = 0; + +struct MyOutputHandler : public nvtt::OutputHandler +{ + MyOutputHandler() : m_ptr(NULL) {} + + virtual void beginImage(int size, int width, int height, int depth, int face, int miplevel) + { + assert(size == OUTPUT_SIZE); + assert(width == WIDTH); + assert(height == HEIGHT); + assert(depth == 1); + assert(face == 0); + assert(miplevel == 0); + + m_ptr = (unsigned char *)s_output; + + if (s_frame == 1) + { + // Save first result as reference. + memcpy(s_reference, s_output, sizeof(int) * OUTPUT_SIZE); + } + else if (s_frame > 1) + { + // Compare against reference. + if (memcmp(s_output, s_reference, sizeof(int) * OUTPUT_SIZE) != 0) + { + printf("Compressed image different to original.\n"); + exit(EXIT_FAILURE); + } + } + } + + virtual bool writeData(const void * data, int size) + { + memcpy(m_ptr, data, size); + m_ptr += size; + return true; + } + + unsigned char * m_ptr; + +}; int main(int argc, char *argv[]) @@ -34,29 +89,37 @@ int main(int argc, char *argv[]) nvtt::InputOptions inputOptions; inputOptions.setTextureLayout(nvtt::TextureType_2D, 1024, 1024); - int * data = (int *)malloc(1024 * 1024 * 4); for (int i = 0; i < 1024 * 1024; i++) { - data[i] = rand(); + s_input[i] = rand(); } - inputOptions.setMipmapData(data, 1024, 1024); + inputOptions.setMipmapData(s_input, 1024, 1024); inputOptions.setMipmapGeneration(false); nvtt::CompressionOptions compressionOptions; + nvtt::OutputOptions outputOptions; + outputOptions.setOutputHeader(false); + + MyOutputHandler outputHandler; + outputOptions.setOutputHandler(&outputHandler); + + nvtt::Compressor compressor; - for (int i = 0; i < 1000; i++) + for (s_frame = 0; s_frame < FRAME_COUNT; s_frame++) { clock_t start = clock(); + printf("compressing frame %d:\n", s_frame); + compressor.process(inputOptions, compressionOptions, outputOptions); clock_t end = clock(); printf("time taken: %.3f seconds\n", float(end-start) / CLOCKS_PER_SEC); } - return 0; + return EXIT_SUCCESS; }