Skip to content

Commit f57af3a

Browse files
authored
Merge pull request #632 from E3SM-Project/dqwu/test_compare_offsets
This PR adds additional test cases to ensure the internal comparison function compare_offsets() correctly handles the differences between 64-bit offset values, including edge cases with extremely large or small values. The new test cases would fail with the current master branch, and they are expected to be fixed by PR #631.
2 parents 074611e + dfd4bfd commit f57af3a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/cunit/test_rearr.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <pio.h>
99
#include <pio_tests.h>
1010
#include <pio_internal.h>
11+
#if SIZEOF_PIO_OFFSET >= 8
12+
#include <stdint.h>
13+
#endif
1114

1215
/* The number of tasks this test should run on. */
1316
#define TARGET_NTASKS 4
@@ -76,6 +79,9 @@ int test_rearranger_opts1(int iosysid)
7679
int test_compare_offsets()
7780
{
7881
mapsort m1, m2, m3;
82+
#if SIZEOF_PIO_OFFSET >= 8
83+
mapsort m_max, m_min;
84+
#endif
7985

8086
m1.rfrom = 0;
8187
m1.soffset = 0;
@@ -86,6 +92,14 @@ int test_compare_offsets()
8692
m3.rfrom = 0;
8793
m3.soffset = 0;
8894
m3.iomap = 1;
95+
#if SIZEOF_PIO_OFFSET >= 8
96+
m_max.rfrom = 0;
97+
m_max.soffset = 0;
98+
m_max.iomap = INT64_MAX;
99+
m_min.rfrom = 0;
100+
m_min.soffset = 0;
101+
m_min.iomap = INT64_MIN;
102+
#endif
89103

90104
/* Return 0 if either or both parameters are null. */
91105
if (compare_offsets(NULL, &m2))
@@ -102,6 +116,35 @@ int test_compare_offsets()
102116
/* m1 and m3 are different. */
103117
if (compare_offsets(&m1, &m3) != -1)
104118
return ERR_WRONG;
119+
120+
#if SIZEOF_PIO_OFFSET >= 8
121+
/* Some representative test cases for 64-bit offset comparison with extreme values */
122+
123+
/* Test: INT64_MAX - INT64_MIN, expected to be positive */
124+
if (compare_offsets(&m_max, &m_min) <= 0)
125+
return ERR_WRONG;
126+
127+
/* Test: INT64_MIN - INT64_MAX, expected to be negative */
128+
if (compare_offsets(&m_min, &m_max) >= 0)
129+
return ERR_WRONG;
130+
131+
/* Test: INT64_MAX - 0, expected to be positive */
132+
if (compare_offsets(&m_max, &m1) <= 0)
133+
return ERR_WRONG;
134+
135+
/* Test: 0 - INT64_MAX, expected to be negative */
136+
if (compare_offsets(&m1, &m_max) >= 0)
137+
return ERR_WRONG;
138+
139+
/* Test: INT64_MIN - 0, expected to be negative */
140+
if (compare_offsets(&m_min, &m1) >= 0)
141+
return ERR_WRONG;
142+
143+
/* Test: 0 - INT64_MIN, expected to be positive */
144+
if (compare_offsets(&m1, &m_min) <= 0)
145+
return ERR_WRONG;
146+
#endif
147+
105148
return 0;
106149
}
107150

0 commit comments

Comments
 (0)