@@ -64,63 +64,70 @@ class test_arch : public ucs::test {
64
64
return result;
65
65
}
66
66
67
- void nt_buffer_transfer_test (ucs_arch_memcpy_hint_t hint) {
67
+ void nt_buffer_transfer_test (ucs_arch_memcpy_hint_t hint)
68
+ {
68
69
#ifndef __AVX__
69
70
UCS_TEST_SKIP_R (" Built without AVX support" );
70
71
#else
71
- int i, j, result, ret = 0 ;
72
- char *test_window_src, *test_window_dst, * src, *dst, * dup ;
72
+ int i, j;
73
+ char *src, *dst;
73
74
size_t len, total_size, test_window_size, hole_size, align;
74
75
75
76
align = 64 ;
76
77
test_window_size = 8 * 1024 ;
77
78
hole_size = 2 * align;
78
79
80
+ auto msg = [&]() {
81
+ std::stringstream ss;
82
+ ss << " using length=" << len << " src_align=" << i
83
+ << " dst_align=" << j;
84
+ return ss.str ();
85
+ };
86
+
79
87
/*
80
88
* Allocate a hole above and below the test_window_size
81
89
* to check for writes beyond the designated area.
82
90
*/
83
91
total_size = test_window_size + (2 * hole_size);
84
92
85
- ret = posix_memalign ((void **)&test_window_src, align, total_size);
86
- if (ret) {
87
- goto src_fail;
88
- }
93
+ auto alloc_aligned = [&align, &total_size]() {
94
+ void *ptr;
95
+ return std::unique_ptr<char >(reinterpret_cast <char *>(
96
+ !posix_memalign (&ptr, align, total_size) ? ptr : nullptr ));
97
+ };
89
98
90
- ret = posix_memalign ((void **)&test_window_dst, align, total_size);
91
- if (ret) {
92
- goto dst_fail;
93
- }
99
+ auto test_window_src = alloc_aligned ();
100
+ auto test_window_dst = alloc_aligned ();
101
+ auto dup = alloc_aligned ();
94
102
95
- ret = posix_memalign ((void **)&dup , align, total_size);
96
- if (ret) {
97
- goto dup_fail;
98
- }
103
+ ASSERT_TRUE (test_window_src);
104
+ ASSERT_TRUE (test_window_dst);
105
+ ASSERT_TRUE (dup );
99
106
100
- src = test_window_src + hole_size;
101
- dst = test_window_dst + hole_size;
107
+ src = test_window_src. get () + hole_size;
108
+ dst = test_window_dst. get () + hole_size;
102
109
103
110
/* Initialize the regions with known patterns */
104
- memset (dup , 0x0 , total_size);
105
- memset (test_window_src, 0xdeaddead , total_size);
106
- memset (test_window_dst, 0x0 , total_size);
111
+ memset (dup . get () , 0x0 , total_size);
112
+ memset (test_window_src. get () , 0xdeaddead , total_size);
113
+ memset (test_window_dst. get () , 0x0 , total_size);
107
114
108
115
len = 0 ;
109
116
110
117
while (len < test_window_size) {
111
118
for (i = 0 ; i < align; i++) {
112
119
for (j = 0 ; j < align; j++) {
113
120
/* Perform the transfer */
114
- ucs_x86_nt_buffer_transfer (dst + i, src + j, len, hint, len);
115
- result = memcmp (src + j, dst + i, len);
116
- EXPECT_EQ (0 , result );
121
+ ucs_x86_nt_buffer_transfer (dst + i, src + j, len, hint,
122
+ len);
123
+ ASSERT_EQ (0 , memcmp (src + j, dst + i, len)) << msg ( );
117
124
118
125
/* reset the copied region back to zero */
119
126
memset (dst + i, 0x0 , len);
120
127
121
128
/* check for any modifications in the holes */
122
- result = memcmp (test_window_dst, dup , total_size);
123
- EXPECT_EQ ( 0 , result );
129
+ ASSERT_EQ ( 0 , memcmp (test_window_dst. get () , dup . get (),
130
+ total_size) );
124
131
}
125
132
}
126
133
/* Check for each len for less than 1k sizes
@@ -132,17 +139,6 @@ class test_arch : public ucs::test {
132
139
len += 53 ;
133
140
}
134
141
}
135
-
136
- free (dup );
137
-
138
- dup_fail:
139
- free (test_window_dst);
140
- dst_fail:
141
- free (test_window_src);
142
- src_fail:
143
- if (ret) {
144
- UCS_TEST_ABORT (" Failed to allocate memory: " << strerror (ret));
145
- }
146
142
#endif
147
143
}
148
144
};
0 commit comments