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

Function test_malloc_bad_params

dpdk/app/test/test_malloc.c:881–932  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

879}
880
881static int
882test_malloc_bad_params(void)
883{
884 const char *type = NULL;
885 size_t size = 0;
886 unsigned align = RTE_CACHE_LINE_SIZE;
887
888 /* rte_malloc expected to return null with inappropriate size */
889 char *bad_ptr = rte_malloc(type, size, align);
890 if (bad_ptr != NULL)
891 goto err_return;
892
893 /* rte_realloc expected to return null with inappropriate size */
894 bad_ptr = rte_realloc(NULL, size, align);
895 if (bad_ptr != NULL)
896 goto err_return;
897
898 /* rte_malloc expected to return null with inappropriate alignment */
899 align = 17;
900 size = 1024;
901
902 bad_ptr = rte_malloc(type, size, align);
903 if (bad_ptr != NULL)
904 goto err_return;
905
906 /* rte_realloc expected to return null with inappropriate alignment */
907 bad_ptr = rte_realloc(NULL, size, align);
908 if (bad_ptr != NULL)
909 goto err_return;
910
911#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
912 /* this test can not be built, will get trapped at compile time! */
913#else
914 /* rte_malloc expected to return null with size will cause overflow */
915 align = RTE_CACHE_LINE_SIZE;
916 size = (size_t)-8;
917
918 bad_ptr = rte_malloc(type, size, align);
919 if (bad_ptr != NULL)
920 goto err_return;
921
922 bad_ptr = rte_realloc(NULL, size, align);
923 if (bad_ptr != NULL)
924 goto err_return;
925#endif
926 return 0;
927
928err_return:
929 /* clean up pointer */
930 rte_free(bad_ptr);
931 return -1;
932}
933
934static int
935check_socket_mem(const struct rte_memseg_list *msl, void *arg)

Callers 1

test_mallocFunction · 0.85

Calls 3

rte_mallocFunction · 0.85
rte_reallocFunction · 0.85
rte_freeFunction · 0.85

Tested by

no test coverage detected