9 #define MAX_NUM_ELEMS (1024 * 1024)
15 #define ALLOC_HEADER_SIZE \
16 ((sizeof(alloc_header) + ABTU_MAX_ALIGNMENT - 1) / ABTU_MAX_ALIGNMENT * \
35 p_header->p_next = NULL;
36 p_header->p_prev = p_alloc_list->
p_tail;
37 if (p_alloc_list->
p_tail) {
39 p_alloc_list->
p_tail = p_header;
41 p_alloc_list->
p_head = p_header;
42 p_alloc_list->
p_tail = p_header;
48 size_t new_size,
void **p_ptr)
66 if (p_alloc_list->
p_head == p_old_header)
67 p_alloc_list->
p_head = p_new_header;
68 if (p_alloc_list->
p_tail == p_old_header)
69 p_alloc_list->
p_tail = p_new_header;
70 p_new_header->
p_prev = p_old_prev_header;
71 if (p_old_prev_header)
72 p_old_prev_header->
p_next = p_new_header;
73 p_new_header->
p_next = p_old_next_header;
74 if (p_old_next_header)
75 p_old_next_header->
p_prev = p_new_header;
99 uint32_t num,
int stride)
104 sizeof(
int) * (p_id_list->
num + num),
105 (
void **)&p_id_list->
ids);
107 for (i = 0; i < num; i++) {
108 p_id_list->
ids[p_id_list->
num + i] =
id + stride * i;
110 p_id_list->
num += num;
118 (
void **)pp_affinity_list);
135 for (i = 1; i < num; i++) {
139 p_id_list->
num = p_base->
num;
141 (
void **)&p_id_list->
ids);
143 for (j = 0; j < p_id_list->
num; j++)
144 p_id_list->
ids[j] = p_base->
ids[j] + stride * i;
154 return c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n';
158 static int consume_int(
const char *str, uint32_t *p_index,
int *p_val)
160 uint32_t index = *p_index;
161 int val = 0, val_sign = 1;
164 char c = *(str + index);
165 if (flag !=
'v' && c ==
'-') {
168 val_sign = -val_sign;
169 }
else if (flag !=
'v' && c ==
'+') {
174 }
else if (
'0' <= c && c <=
'9') {
177 val = val * 10 + (int)(c -
'0');
182 *p_val = val * val_sign;
195 static int consume_pint(
const char *str, uint32_t *p_index,
int *p_val)
197 uint32_t index = *p_index;
211 uint32_t index = *p_index;
213 char c = *(str + index);
215 *p_index = index + 1;
238 ret =
id_list_add(p_alloc_list, p_affinity_id_list, val, 1, 1);
240 *pp_affinity_id_list = p_affinity_id_list;
245 int id, num = 1, stride = 1;
265 id_list_add(p_alloc_list, p_affinity_id_list,
id, num, stride);
277 *pp_affinity_id_list = p_affinity_id_list;
285 const char *affinity_str,
298 int num = 1, stride = 1;
318 ret =
list_add(p_alloc_list, p_affinity_list, p_id_list, num, stride);
330 *pp_affinity_list = p_affinity_list;
342 int ret =
parse_list(&tmp_alloc_list, affinity_str, &p_affinity_list);
351 *pp_affinity_list = p_affinity_list;
358 if (p_affinity_list) {
370 for (i = 0; i < a->
num; i++) {
373 if (a_id->
num != b_id->
num)
375 for (j = 0; j < a_id->
num; j++) {
376 if (a_id->
ids[j] != b_id->
ids[j])
383 static int is_equal_str(
const char *a_str,
const char *b_str)
389 int ret1 =
parse_list(&tmp_alloc_list1, a_str, &a);
390 int ret2 =
parse_list(&tmp_alloc_list2, b_str, &b);
397 static int is_err_str(
const char *str)
401 int ret =
parse_list(&tmp_alloc_list, str, &a);
409 static void test_parse(
void)
412 assert(!is_err_str(
"++1"));
413 assert(!is_err_str(
"+-1"));
414 assert(!is_err_str(
"+-+-1"));
415 assert(!is_err_str(
"+0"));
416 assert(!is_err_str(
"-0"));
417 assert(!is_err_str(
"-9:1:-9"));
418 assert(!is_err_str(
"-9:1:0"));
419 assert(!is_err_str(
"-9:1:9"));
420 assert(!is_err_str(
"0:1:-9"));
421 assert(!is_err_str(
"0:1:0"));
422 assert(!is_err_str(
"0:1:9"));
423 assert(!is_err_str(
"9:1:-9"));
424 assert(!is_err_str(
"9:1:0"));
425 assert(!is_err_str(
"9:1:9"));
426 assert(!is_err_str(
"{-9:1:-9}"));
427 assert(!is_err_str(
"{-9:1:0}"));
428 assert(!is_err_str(
"{-9:1:9}"));
429 assert(!is_err_str(
"{0:1:-9}"));
430 assert(!is_err_str(
"{0:1:0}"));
431 assert(!is_err_str(
"{0:1:9}"));
432 assert(!is_err_str(
"{9:1:-9}"));
433 assert(!is_err_str(
"{9:1:0}"));
434 assert(!is_err_str(
"{9:1:9}"));
435 assert(!is_err_str(
"1,2,3"));
436 assert(!is_err_str(
"1,2,{1,2}"));
437 assert(!is_err_str(
"1,2,{1:2}"));
438 assert(!is_err_str(
"1:2,{1:2}"));
439 assert(!is_err_str(
"1:2:1,2"));
440 assert(!is_err_str(
" 1 : +2 , { -1 : \r 2\n:2}\n"));
442 assert(is_err_str(
""));
443 assert(is_err_str(
"{}"));
444 assert(is_err_str(
"+ 1"));
445 assert(is_err_str(
"+ +1"));
446 assert(is_err_str(
"+ -1"));
447 assert(is_err_str(
"1:"));
448 assert(is_err_str(
"1:2:"));
449 assert(is_err_str(
"1:2,"));
450 assert(is_err_str(
"1:-2"));
451 assert(is_err_str(
"1:0"));
452 assert(is_err_str(
"1:-2:4"));
453 assert(is_err_str(
"1:0:4"));
454 assert(is_err_str(
"1:1:1:"));
455 assert(is_err_str(
"1:1:1:1"));
456 assert(is_err_str(
"1:1:1:1,1"));
457 assert(is_err_str(
"{1:2:3},"));
458 assert(is_err_str(
"{1:2:3}:"));
459 assert(is_err_str(
"{1:2:3}:2:"));
460 assert(is_err_str(
"{:2:3}"));
461 assert(is_err_str(
"{{2:3}}"));
462 assert(is_err_str(
"{2:3}}"));
463 assert(is_err_str(
"2:3}"));
464 assert(is_err_str(
"{1:2:3"));
465 assert(is_err_str(
"{1,2,}"));
466 assert(is_err_str(
"{1:-2}"));
467 assert(is_err_str(
"{1:0}"));
468 assert(is_err_str(
"{1:-2:4}"));
469 assert(is_err_str(
"{1:0:4}"));
471 assert(is_equal_str(
"{1},{2},{3},{4}",
"1,2,3,4"));
472 assert(is_equal_str(
"{1:4:1}",
"{1,2,3,4}"));
473 assert(is_equal_str(
"{1:4}",
"{1,2,3,4}"));
474 assert(is_equal_str(
"1:2,3:2",
"1,2,3,4"));
475 assert(is_equal_str(
"{1:2},3:2",
"{1,2},3,4"));
476 assert(is_equal_str(
"{1:1:4},{2:1:-4},{3:1:0},{4:1}",
"1,2,3,4"));
477 assert(is_equal_str(
"{3:4:-1}",
"{3,2,1,0}"));
478 assert(is_equal_str(
"3:4:-1,-1",
"3,2,1,0,-1"));
479 assert(is_equal_str(
"{1:2:3}:1",
"{1,4}"));
480 assert(is_equal_str(
"{1:2:3}:3",
"{1,4},{2,5},{3,6}"));
481 assert(is_equal_str(
"{1:2:3}:3:2",
"{1,4},{3,6},{5,8}"));
482 assert(is_equal_str(
"{1:2:3}:3:-2",
"{1,4},{-1,2},{-3,0}"));
483 assert(is_equal_str(
"{1:2:3}:3:-2,1",
"{1,4},{-1,2},{-3,0},1"));
484 assert(is_equal_str(
"{-2:3:-2}:2:-4",
"{-2,-4,-6},{-6,-8,-10}"));