MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_parse_num_valid

Function test_parse_num_valid

dpdk/app/test/test_cmdline_num.c:404–580  ·  view source on GitHub ↗

test valid parameters and data */

Source from the content-addressed store, hash-verified

402
403/* test valid parameters and data */
404int
405test_parse_num_valid(void)
406{
407 int ret = 0;
408 enum cmdline_numtype type;
409 unsigned i;
410 char buf[CMDLINE_TEST_BUFSIZE];
411 uint64_t result;
412 cmdline_parse_token_num_t token;
413
414 /** valid strings **/
415
416 /* cycle through all possible parsed types */
417 for (type = RTE_UINT8; type <= RTE_INT64; type++) {
418 token.num_data.type = type;
419
420 /* test positive strings */
421 for (i = 0; i < RTE_DIM(num_valid_positive_strs); i++) {
422 result = 0;
423 memset(&buf, 0, sizeof(buf));
424
425 cmdline_get_help_num((cmdline_parse_token_hdr_t*)&token,
426 buf, sizeof(buf));
427
428 ret = cmdline_parse_num((cmdline_parse_token_hdr_t*) &token,
429 num_valid_positive_strs[i].str,
430 (void*)&result, sizeof(result));
431
432 /* if it should have passed but didn't, or if it should have failed but didn't */
433 if ((ret < 0) == (can_parse_unsigned(num_valid_positive_strs[i].result, type) > 0)) {
434 printf("Error: parser behaves unexpectedly when parsing %s as %s!\n",
435 num_valid_positive_strs[i].str, buf);
436 return -1;
437 }
438 /* check if result matches what it should have matched
439 * since unsigned numbers don't care about number of bits, we can just convert
440 * everything to uint64_t without any worries. */
441 if (ret > 0 && num_valid_positive_strs[i].result != result) {
442 printf("Error: parsing %s as %s failed: result mismatch!\n",
443 num_valid_positive_strs[i].str, buf);
444 return -1;
445 }
446 }
447
448 /* test negative strings */
449 for (i = 0; i < RTE_DIM(num_valid_negative_strs); i++) {
450 result = 0;
451 memset(&buf, 0, sizeof(buf));
452
453 cmdline_get_help_num((cmdline_parse_token_hdr_t*)&token,
454 buf, sizeof(buf));
455
456 ret = cmdline_parse_num((cmdline_parse_token_hdr_t*) &token,
457 num_valid_negative_strs[i].str,
458 (void*)&result, sizeof(result));
459
460 /* if it should have passed but didn't, or if it should have failed but didn't */
461 if ((ret < 0) == (can_parse_signed(num_valid_negative_strs[i].result, type) > 0)) {

Callers 1

test_cmdlineFunction · 0.85

Calls 6

memsetFunction · 0.85
cmdline_get_help_numFunction · 0.85
cmdline_parse_numFunction · 0.85
can_parse_unsignedFunction · 0.85
can_parse_signedFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected