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

Function test_rte_malloc_validate

dpdk/app/test/test_malloc.c:790–862  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

788} while (0)
789
790static int
791test_rte_malloc_validate(void)
792{
793 const size_t request_size = 1024;
794 size_t allocated_size;
795 char *data_ptr = rte_malloc(NULL, request_size, RTE_CACHE_LINE_SIZE);
796#ifdef RTE_MALLOC_DEBUG
797 int retval;
798 char *over_write_vals = NULL;
799#endif
800
801 if (data_ptr == NULL) {
802 printf("%s: %d - Allocation error\n", __func__, __LINE__);
803 return -1;
804 }
805
806 /* check that a null input returns -1 */
807 if (rte_malloc_validate(NULL, NULL) != -1)
808 err_return();
809
810 /* check that we get ok on a valid pointer */
811 if (rte_malloc_validate(data_ptr, &allocated_size) < 0)
812 err_return();
813
814 /* check that the returned size is ok */
815 if (allocated_size < request_size)
816 err_return();
817
818#ifdef RTE_MALLOC_DEBUG
819
820 /****** change the header to be bad */
821 char save_buf[64];
822 over_write_vals = (char *)((uintptr_t)data_ptr - sizeof(save_buf));
823 /* first save the data as a backup before overwriting it */
824 memcpy(save_buf, over_write_vals, sizeof(save_buf));
825 memset(over_write_vals, 1, sizeof(save_buf));
826 /* then run validate */
827 retval = rte_malloc_validate(data_ptr, NULL);
828 /* finally restore the data again */
829 memcpy(over_write_vals, save_buf, sizeof(save_buf));
830 /* check we previously had an error */
831 if (retval != -1)
832 err_return();
833
834 /* check all ok again */
835 if (rte_malloc_validate(data_ptr, &allocated_size) < 0)
836 err_return();
837
838 /**** change the trailer to be bad */
839 over_write_vals = (char *)((uintptr_t)data_ptr + allocated_size);
840 /* first save the data as a backup before overwriting it */
841 memcpy(save_buf, over_write_vals, sizeof(save_buf));
842 memset(over_write_vals, 1, sizeof(save_buf));
843 /* then run validate */
844 retval = rte_malloc_validate(data_ptr, NULL);
845 /* finally restore the data again */
846 memcpy(over_write_vals, save_buf, sizeof(save_buf));
847 if (retval != -1)

Callers 1

test_mallocFunction · 0.85

Calls 6

rte_mallocFunction · 0.85
rte_malloc_validateFunction · 0.85
memsetFunction · 0.85
rte_freeFunction · 0.85
printfFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected