fix for old systems

This commit is contained in:
2025-07-15 23:48:07 +09:00
parent 8a722d5789
commit 2c63c56e0e
4 changed files with 25 additions and 21 deletions

View File

@ -3,6 +3,12 @@
for i in $@; do :; done
script="$i"
escape_regex() {
local str="$1"
## escape [, ], {, (, \, $, *, . ^, ), }
printf '%s\n' "$str" | sed -r -e 's/[][{(\$*.^)}]/\\&/g'
}
run_partfile() {
l_cmd="";
l_nargs=$#
@ -21,7 +27,9 @@ run_partfile() {
l_partfile="$1"
l_cmd="$l_cmd $l_partfile"
l_expected_errinfo=$(grep -n -o -E "##ERROR: .+" "$l_partfile" 2>/dev/null)
## old greps don't support -o. use sed to mimic it.
##l_expected_errinfo=$(grep -n -o -E "##ERROR: .+" "$l_partfile" 2>/dev/null)
l_expected_errinfo=$(grep -n -E "##ERROR: .+" "$l_partfile" 2>/dev/null | sed -r -n 's/^([0-9]*):.*(##ERROR: .*)/\1:\2/p')
[ -z "$l_expected_errinfo" ] && {
echo "ERROR: INVALID TESTER - $l_script($l_partno) contains no ERROR information"
return 1
@ -33,8 +41,9 @@ run_partfile() {
l_expected_errmsg=$(echo $l_expected_errinfo | cut -c${l_xlen}-)
l_output=`$l_cmd 2>&1`
## the regular expression is not escaped properly. the error information must not
## include specifial regex characters to avoid problems.
echo "$l_output" | grep -E "ERROR: .+ LINE ${l_expected_errline} .+ FILE ${l_partfile} - ${l_expected_errmsg}" >/dev/null 2>&1 || {
## include special regex characters to avoid problems.
l_expected_errmsg_esc=$(escape_regex "${l_expected_errmsg}")
echo "$l_output" | grep -E "ERROR: .+ LINE ${l_expected_errline} .+ FILE ${l_partfile} - ${l_expected_errmsg_esc}" >/dev/null 2>&1 || {
echo "ERROR: error not raised at line $l_expected_errline - $l_script($l_partno) - $l_output"
return 1
}
@ -45,7 +54,10 @@ run_partfile() {
ever_failed=0
partfile=`mktemp`
## [NOTE]
## some old mktemp(e.g mktemp 1.5 on rhel 2.1) always required the template.
## these days, newer ones don't need it.
partfile=`mktemp tmp.XXXXXXXXXX`
partno=0
partlines=0
> "$partfile"

View File

@ -26,6 +26,7 @@ int main(int argc, char* argv[])
clock_t start_time, end_time;
double malloc_time = 0.0, free_time = 0.0;
void **ptr_array;
size_t i;
if (argc >= 3)
{
@ -46,7 +47,7 @@ int main(int argc, char* argv[])
}
start_time = clock();
for (size_t i = 0; i < num_iterations; ++i) {
for (i = 0; i < num_iterations; ++i) {
size_t size = random_size(max_alloc_size);
/*ptr_array[i] = malloc(size);*/
ptr_array[i] = HAWK_MMGR_ALLOC(&xma_mmgr, size);
@ -64,7 +65,7 @@ int main(int argc, char* argv[])
malloc_time = (double)(end_time - start_time) / CLOCKS_PER_SEC;
start_time = clock();
for (size_t i = 0; i < num_iterations; ++i) {
for (i = 0; i < num_iterations; ++i) {
/*free(ptr_array[i]);*/
HAWK_MMGR_FREE(&xma_mmgr, ptr_array[i]);
}

View File

@ -108,6 +108,7 @@ int main(int argc, char* argv[])
Allocation* allocations; /* pool of active allocations */
size_t num_active = 0;
size_t i;
clock_t start_time, end_time;
double malloc_time = 0.0, free_time = 0.0;
@ -144,7 +145,7 @@ int main(int argc, char* argv[])
srand((unsigned int)time(NULL));
start_time = clock();
for (size_t i = 0; i < num_iterations; ++i)
for (i = 0; i < num_iterations; ++i)
{
int do_alloc = (num_active == 0) || (rand() % 2 == 0 && num_active < max_alloc_active);
@ -163,13 +164,14 @@ int main(int argc, char* argv[])
++num_active;
} else {
/* free a random active allocation */
clock_t t1, t2;
size_t index = rand() % num_active;
void *ptr_to_free = allocations[index].ptr;
clock_t t1 = clock();
t1 = clock();
/*free(ptr_to_free); */
HAWK_MMGR_FREE(&xma_mmgr, ptr_to_free);
clock_t t2 = clock();
t2 = clock();
free_time += (double)(t2 - t1) / CLOCKS_PER_SEC;
/* replace with last active allocation */
@ -182,7 +184,7 @@ int main(int argc, char* argv[])
/* hawk_xma_dump(xma_mmgr.ctx, print_xma, HAWK_NULL); */
/* Free remaining allocations */
for (size_t i = 0; i < num_active; ++i) {
for (i = 0; i < num_active; ++i) {
/* free(allocations[i].ptr); */
HAWK_MMGR_FREE(&xma_mmgr, allocations[i].ptr);
}