xrif
A fast lossless compression system
xrif_test_difference_pixel_whitenoise.c
Go to the documentation of this file.
1 /** \file xrif_test_difference_pixel_whitenoise.c
2  * \brief Test the pixel differencing method with white noise.
3  *
4  * \author Jared R. Males (jaredmales@gmail.com)
5  *
6  * \ingroup xrif_test_files
7  */
8 
9 /* This file is part of the xrif library.
10 
11 Copyright (c) 2019, 2020, 2021 The Arizona Board of Regents on behalf of The
12 University of Arizona
13 
14 All rights reserved.
15 
16 Developed by: The Arizona Board of Regents on behalf of the
17 University of Arizona.
18 
19 Redistribution and use for noncommercial purposes in source and
20 binary forms, with or without modification, are permitted provided
21 that the following conditions are met:
22 
23 1. The software is used solely for noncommercial purposes.
24 
25 2. Redistributions of source code must retain the above copyright
26 notice, terms and conditions specified herein and the disclaimer
27 specified in Section 4 below.
28 
29 3. Redistributions in binary form must reproduce the above
30 copyright notice, this list of conditions and the following
31 disclaimer in the documentation and/or other materials provided
32 with the distribution.
33 
34 4. Neither the name of the Arizona Board of Regents, the University
35 of Arizona nor the names of other contributors may be used to
36 endorse or promote products derived from this software without
37 specific prior written permission.
38 
39 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
41 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
42 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
43 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
44 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
45 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
46 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 OF THE POSSIBILITY OF SUCH DAMAGE.
51 
52 Arizona Required Clauses:
53 
54 1.1. Arbitration. The parties agree that if a dispute arises
55 between them concerning this Agreement, the parties may be required
56 to submit the matter to arbitration pursuant to Arizona law.
57 
58 1.2. Applicable Law and Venue. This Agreement shall be interpreted
59 pursuant to the laws of the State of Arizona. Any arbitration or
60 litigation between the Parties shall be conducted in Pima County,
61 ARIZONA, and LICENSEE hereby submits to venue and jurisdiction in
62 Pima County, ARIZONA.
63 
64 1.3. Non-Discrimination. The Parties agree to be bound by state and
65 federal laws and regulations governing equal opportunity and non-
66 discrimination and immigration.
67 
68 1.4. Appropriation of Funds. The Parties recognize that performance
69 by ARIZONA may depend upon appropriation of funds by the State
70 Legislature of ARIZONA. If the Legislature fails to appropriate the
71 necessary funds, or if ARIZONA’S appropriation is reduced during
72 the fiscal year, ARIZONA may cancel this Agreement without further
73 duty or obligation. ARIZONA will notify LICENSEE as soon as
74 reasonably possible after it knows of the loss of funds.
75 
76 1.5. Conflict of Interest. This Agreement is subject to the
77 provisions of A.R.S. 38-511 and other conflict of interest
78 regulations. Within three years of the EFFECTIVE DATE, ARIZONA may
79 cancel this Agreement if any person significantly involved in
80 initiating, negotiating, drafting, securing, or creating this
81 Agreement for or on behalf of ARIZONA becomes an employee or
82 consultant in any capacity of LICENSEE with respect to the subject
83 matter of this Agreement.
84 
85 */
86 
87 #include <check.h>
88 #include <stdlib.h>
89 #include <stdio.h>
90 #include <time.h>
91 #include <limits.h>
92 
93 #include "../src/xrif.h"
94 
95 #include "randutils.h"
96 
97 #ifndef XRIF_TEST_TRIALS
98  #define XRIF_TEST_TRIALS (2)
99 #endif
100 
101 int test_trials;
102 
103 /************************************************************/
104 /* Fuzz testing differencing with the pixel method
105 /************************************************************/
106 
107 
108 int ws[] = {2,4,8,21, 33, 47, 64}; //widths of images
109 int hs[] = {2,4,8,21, 33, 47, 64}; //heights of images
110 int ps[] = {1,2,4,5,27,63,64}; //planes of the cube
111 
112 
113 
114 /** Verify pixel differencing for int16_t
115  * Verify that xrif difference/un-difference cycle using the first pixel of each works with white noise For int16_t.
116  * \anchor diff_pixel_int16_white
117  */
118 START_TEST (diff_pixel_int16_white)
119 {
120  fprintf(stderr, "Testing pixel differencing for signed 16-bit white noise.\n");
121  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_INT16)
122  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PIXEL)
123  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
124  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
125  #define XRIF_TESTLOOP_FILL 1
126  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
127  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
128  #define XRIF_TESTLOOP_NOPERF
129 
130  #include "testloop.c"
131 }
132 END_TEST;
133 
134 /** Verify pixel differencing for uint16_t
135  * Verify that xrif difference/un-difference cycle using the first pixel of each works with white noise For uint16_t.
136  * \anchor diff_pixel_uint16_white
137  */
138 START_TEST (diff_pixel_uint16_white)
139 {
140  fprintf(stderr, "Testing pixel differencing for unsigned 16-bit white noise.\n");
141  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_UINT16)
142  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PIXEL)
143  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
144  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
145  #define XRIF_TESTLOOP_FILL 1
146  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
147  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
148  #define XRIF_TESTLOOP_NOPERF
149 
150  #include "testloop.c"
151 }
152 END_TEST;
153 
154 /** Verify pixel differencing for int32_t
155  * Verify that xrif difference/un-difference cycle using the first pixel of each works with white noise For int32_t.
156  * \anchor diff_pixel_int32_white
157  */
158 START_TEST (diff_pixel_int32_white)
159 {
160  fprintf(stderr, "Testing pixel differencing for signed 32-bit white noise.\n");
161  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_INT32)
162  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PIXEL)
163  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
164  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
165  #define XRIF_TESTLOOP_FILL 1
166  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
167  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
168  #define XRIF_TESTLOOP_NOPERF
169 
170  #include "testloop.c"
171 }
172 END_TEST;
173 
174 /** Verify pixel differencing for uint32_t
175  * Verify that xrif difference/un-difference cycle using the first pixel of each works with white noise For uint32_t.
176  * \anchor diff_pixel_uint32_white
177  */
178 START_TEST (diff_pixel_uint32_white)
179 {
180  fprintf(stderr, "Testing pixel differencing for unsigned 32-bit white noise.\n");
181  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_UINT32)
182  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PIXEL)
183  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
184  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
185  #define XRIF_TESTLOOP_FILL 1
186  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
187  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
188  #define XRIF_TESTLOOP_NOPERF
189 
190  #include "testloop.c"
191 }
192 END_TEST;
193 
194 /** Verify pixel differencing for int64_t
195  * Verify that xrif difference/un-difference cycle using the first pixel of each works with white noise For int64_t.
196  * \anchor diff_pixel_int64_white
197  */
198 START_TEST (diff_pixel_int64_white)
199 {
200  fprintf(stderr, "Testing pixel differencing for signed 64-bit white noise.\n");
201  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_INT64)
202  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PIXEL)
203  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
204  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
205  #define XRIF_TESTLOOP_FILL 1
206  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
207  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
208  #define XRIF_TESTLOOP_NOPERF
209 
210  #include "testloop.c"
211 }
212 END_TEST;
213 
214 /** Verify pixel differencing for uint64_t
215  * Verify that xrif difference/un-difference cycle using the first pixel of each works with white noise For uint64_t.
216  * \anchor diff_pixel_uint64_white
217  */
218 START_TEST (diff_pixel_uint64_white)
219 {
220  fprintf(stderr, "Testing pixel differencing for unsigned 64-bit white noise.\n");
221  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_UINT64)
222  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PIXEL)
223  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
224  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
225  #define XRIF_TESTLOOP_FILL 1
226  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
227  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
228  #define XRIF_TESTLOOP_NOPERF
229 
230  #include "testloop.c"
231 }
232 END_TEST;
233 
234 Suite * whitenoise_suite(void)
235 {
236  Suite *s;
237  TCase *tc_core16, *tc_core32, *tc_core64;
238 
239  s = suite_create("White Noise - Difference Pixel");
240 
241  /* 16-bit Core test case */
242  tc_core16 = tcase_create("16 bit white noise");
243 
244  tcase_set_timeout(tc_core16, 1e9);
245 
246  tcase_add_test(tc_core16, diff_pixel_int16_white);
247  tcase_add_test(tc_core16, diff_pixel_uint16_white);
248 
249  suite_add_tcase(s, tc_core16);
250 
251  /* 32-bit Core test case */
252  tc_core32 = tcase_create("32 bit white noise");
253 
254  tcase_set_timeout(tc_core32, 1e9);
255 
256  tcase_add_test(tc_core32, diff_pixel_int32_white);
257  tcase_add_test(tc_core32, diff_pixel_uint32_white);
258 
259  suite_add_tcase(s, tc_core32);
260 
261  /* 64-bit Core test case */
262  tc_core64 = tcase_create("64 bit white noise");
263 
264  tcase_set_timeout(tc_core64, 1e9);
265 
266  tcase_add_test(tc_core64, diff_pixel_int64_white);
267  tcase_add_test(tc_core64, diff_pixel_uint64_white);
268 
269  suite_add_tcase(s, tc_core64);
270 
271  return s;
272 }
273 
274 int main( int argc,
275  char ** argv
276  )
277 {
278 
279  extern int test_trials;
280 
281  test_trials = XRIF_TEST_TRIALS;
282 
283  if(argc == 2)
284  {
285  test_trials = atoi(argv[1]);
286  }
287 
288  fprintf(stderr, "running %d trials per format\n", test_trials);
289 
290  int number_failed;
291  Suite *s;
292  SRunner *sr;
293 
294  // Intialize the random number sequence
295  srand((unsigned) time(NULL));
296 
297 
298 
299  s = whitenoise_suite();
300  sr = srunner_create(s);
301 
302  srunner_run_all(sr, CK_NORMAL);
303  number_failed = srunner_ntests_failed(sr);
304  srunner_free(sr);
305 
306  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
307 
308 }
309 
START_TEST
START_TEST(diff_pixel_int16_white)
Definition: xrif_test_difference_pixel_whitenoise.c:118