diff --git a/tools/testing/selftests/vm/charge_reserved_hugetlb.sh b/tools/testing/selftests/vm/charge_reserved_hugetlb.sh index efd68093ce3e9..18d33684faade 100755 --- a/tools/testing/selftests/vm/charge_reserved_hugetlb.sh +++ b/tools/testing/selftests/vm/charge_reserved_hugetlb.sh @@ -169,19 +169,36 @@ function write_hugetlbfs_and_get_usage() { echo reserved_usage="$reserved_before" echo expect_failure is "$expect_failure" + output=$(mktemp) set +e if [[ "$method" == "1" ]] || [[ "$method" == 2 ]] || [[ "$private" == "-r" ]] && [[ "$expect_failure" != 1 ]]; then bash write_hugetlb_memory.sh "$size" "$populate" "$write" \ - "$cgroup" "$path" "$method" "$private" "-l" "$reserve" & + "$cgroup" "$path" "$method" "$private" "-l" "$reserve" 2>&1 | tee $output & local write_result=$? + local write_pid=$! - if [[ "$reserve" != "-n" ]]; then - wait_for_hugetlb_memory_to_get_reserved "$cgroup" "$size" - elif [[ "$populate" == "-o" ]] || [[ "$write" == "-w" ]]; then + until grep -q -i "DONE" $output; do + echo waiting for DONE signal. + if ! ps $write_pid > /dev/null + then + echo "FAIL: The write died" + cleanup + exit 1 + fi + sleep 0.5 + done + + echo ================= write_hugetlb_memory.sh output is: + cat $output + echo ================= end output. + + if [[ "$populate" == "-o" ]] || [[ "$write" == "-w" ]]; then wait_for_hugetlb_memory_to_get_written "$cgroup" "$size" + elif [[ "$reserve" != "-n" ]]; then + wait_for_hugetlb_memory_to_get_reserved "$cgroup" "$size" else # This case doesn't produce visible effects, but we still have # to wait for the async process to start and execute... @@ -227,7 +244,7 @@ function cleanup_hugetlb_memory() { set +e local cgroup="$1" if [[ "$(pgrep -f write_to_hugetlbfs)" != "" ]]; then - echo kiling write_to_hugetlbfs + echo killing write_to_hugetlbfs killall -2 write_to_hugetlbfs wait_for_hugetlb_memory_to_get_depleted $cgroup fi diff --git a/tools/testing/selftests/vm/write_to_hugetlbfs.c b/tools/testing/selftests/vm/write_to_hugetlbfs.c index 85811c3384a10..7f75ad5f7b580 100644 --- a/tools/testing/selftests/vm/write_to_hugetlbfs.c +++ b/tools/testing/selftests/vm/write_to_hugetlbfs.c @@ -207,13 +207,13 @@ int main(int argc, char **argv) } printf("shmid: 0x%x, shmget key:%d\n", shmid, key); - shmaddr = shmat(shmid, NULL, 0); - if (shmaddr == (char *)-1) { + ptr = shmat(shmid, NULL, 0); + if (ptr == (int *)-1) { perror("Shared memory attach failure"); shmctl(shmid, IPC_RMID, NULL); exit(2); } - printf("shmaddr: %p\n", shmaddr); + printf("shmaddr: %p\n", ptr); break; default: @@ -223,25 +223,7 @@ int main(int argc, char **argv) if (write) { printf("Writing to memory.\n"); - if (method != SHM) { - memset(ptr, 1, size); - } else { - printf("Starting the writes:\n"); - for (i = 0; i < size; i++) { - shmaddr[i] = (char)(i); - if (!(i % (1024 * 1024))) - printf("."); - } - printf("\n"); - - printf("Starting the Check..."); - for (i = 0; i < size; i++) - if (shmaddr[i] != (char)i) { - printf("\nIndex %lu mismatched\n", i); - exit(3); - } - printf("Done.\n"); - } + memset(ptr, 1, size); } if (want_sleep) { @@ -253,7 +235,7 @@ int main(int argc, char **argv) sleep(100); } - switch (method == HUGETLBFS) { + if (method == HUGETLBFS) { close(fd); }