xrif
A fast lossless compression system
xrif_test_difference_previous_whitenoise.c
Go to the documentation of this file.
1 /** \file xrif_test_difference_previous_whitenoise.c
2  * \brief Test the previous 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 previous 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 /** Verify previous differencing for int16_t
113  * Verify that xrif difference/un-difference cycle using the previous image works with white noise for int16_t.
114  * \anchor diff_previous_int16_white
115  */
116 START_TEST (diff_previous_int16_white)
117 {
118  fprintf(stderr, "Testing previous differencing for signed 16-bit white noise.\n");
119  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_INT16)
120  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PREVIOUS)
121  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
122  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
123  #define XRIF_TESTLOOP_FILL 1
124  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
125  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
126  #define XRIF_TESTLOOP_NOPERF
127 
128  #include "testloop.c"
129 }
130 END_TEST;
131 
132 /** Verify previous differencing for uint16_t
133  * Verify that xrif difference/un-difference cycle using the previous image works with white noise for uint16_t.
134  * \anchor diff_previous_uint16_white
135  */
136 START_TEST (diff_previous_uint16_white)
137 {
138  fprintf(stderr, "Testing previous differencing for unsigned 16-bit white noise.\n");
139 
140  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_UINT16)
141  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PREVIOUS)
142  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
143  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
144  #define XRIF_TESTLOOP_FILL 1
145  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
146  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
147  #define XRIF_TESTLOOP_NOPERF
148 
149  #include "testloop.c"
150 }
151 END_TEST;
152 
153 /** Verify previous differencing for int32_t
154  * Verify that xrif difference/un-difference cycle using the previous image works with white noise for int32_t.
155  * \anchor diff_previous_int32_white
156  */
157 START_TEST (diff_previous_int32_white)
158 {
159  fprintf(stderr, "Testing previous differencing for signed 32-bit white noise.\n");
160  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_INT32)
161  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PREVIOUS)
162  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
163  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
164  #define XRIF_TESTLOOP_FILL 1
165  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
166  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
167  #define XRIF_TESTLOOP_NOPERF
168 
169  #include "testloop.c"
170 }
171 END_TEST;
172 
173 /** Verify previous differencing for uint32_t
174  * Verify that xrif difference/un-difference cycle using the previous image works with white noise for uint32_t.
175  * \anchor diff_previous_uint32_white
176  */
177 START_TEST (diff_previous_uint32_white)
178 {
179  fprintf(stderr, "Testing previous differencing for unsigned 32-bit white noise.\n");
180  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_UINT32)
181  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PREVIOUS)
182  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
183  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
184  #define XRIF_TESTLOOP_FILL 1
185  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
186  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
187  #define XRIF_TESTLOOP_NOPERF
188 
189  #include "testloop.c"
190 }
191 END_TEST;
192 
193 /** Verify previous differencing for int64_t
194  * Verify that xrif difference/un-difference cycle using the previous image works with white noise for int64_t.
195  * \anchor diff_previous_int64_white
196  */
197 START_TEST (diff_previous_int64_white)
198 {
199  fprintf(stderr, "Testing previous differencing for signed 64-bit white noise.\n");
200  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_INT64)
201  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PREVIOUS)
202  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
203  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
204  #define XRIF_TESTLOOP_FILL 1
205  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
206  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
207  #define XRIF_TESTLOOP_NOPERF
208 
209  #include "testloop.c"
210 }
211 END_TEST;
212 
213 /** Verify previous differencing for uint64_t
214  * Verify that xrif difference/un-difference cycle using the previous image works with white noise for uint64_t.
215  * \anchor diff_previous_uint64_white
216  */
217 START_TEST (diff_previous_uint64_white)
218 {
219  fprintf(stderr, "Testing previous differencing for unsigned 64-bit white noise.\n");
220  #define XRIF_TESTLOOP_TYPECODE (XRIF_TYPECODE_UINT64)
221  #define XRIF_TESTLOOP_DIFFERENCE (XRIF_DIFFERENCE_PREVIOUS)
222  #define XRIF_TESTLOOP_REORDER (XRIF_REORDER_BYTEPACK_RENIBBLE)
223  #define XRIF_TESTLOOP_COMPRESS (XRIF_COMPRESS_LZ4)
224  #define XRIF_TESTLOOP_FILL 1
225  #define XRIF_TESTLOOP_ENCODE xrif_difference_previous
226  #define XRIF_TESTLOOP_DECODE xrif_undifference_previous
227  #define XRIF_TESTLOOP_NOPERF
228 
229  #include "testloop.c"
230 }
231 END_TEST;
232 
233 Suite * whitenoise_suite(void)
234 {
235  Suite *s;
236  TCase *tc_core16, *tc_core32, *tc_core64;
237 
238  s = suite_create("White Noise - Difference Previous");
239 
240  /* 16-bit Core test case */
241  tc_core16 = tcase_create("16 bit white noise");
242 
243  tcase_set_timeout(tc_core16, 1e9);
244 
245  tcase_add_test(tc_core16, diff_previous_int16_white);
246  tcase_add_test(tc_core16, diff_previous_uint16_white);
247 
248  suite_add_tcase(s, tc_core16);
249 
250  /* 32-bit Core test case */
251  tc_core32 = tcase_create("32 bit white noise");
252 
253  tcase_set_timeout(tc_core32, 1e9);
254 
255  tcase_add_test(tc_core32, diff_previous_int32_white);
256  tcase_add_test(tc_core32, diff_previous_uint32_white);
257 
258  suite_add_tcase(s, tc_core32);
259 
260  /* 64-bit Core test case */
261  tc_core64 = tcase_create("64 bit white noise");
262 
263  tcase_set_timeout(tc_core64, 1e9);
264 
265  tcase_add_test(tc_core64, diff_previous_int64_white);
266  tcase_add_test(tc_core64, diff_previous_uint64_white);
267 
268  suite_add_tcase(s, tc_core64);
269 
270  return s;
271 }
272 
273 int main( int argc,
274  char ** argv
275  )
276 {
277 
278  extern int test_trials;
279 
280  test_trials = XRIF_TEST_TRIALS;
281 
282  if(argc == 2)
283  {
284  test_trials = atoi(argv[1]);
285  }
286 
287  fprintf(stderr, "running %d trials per format\n", test_trials);
288 
289  int number_failed;
290  Suite *s;
291  SRunner *sr;
292 
293  // Intialize the random number sequence
294  srand((unsigned) time(NULL));
295 
296  s = whitenoise_suite();
297  sr = srunner_create(s);
298 
299  srunner_run_all(sr, CK_NORMAL);
300  number_failed = srunner_ntests_failed(sr);
301  srunner_free(sr);
302 
303  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
304 
305 }
306 
START_TEST
START_TEST(diff_previous_int16_white)
Definition: xrif_test_difference_previous_whitenoise.c:116