selftests/powerpc: Add generic read/write file util

File read/write is reimplemented in about 5 different ways in the
various PowerPC selftests. This indicates it should be a common util.

Add a common read_file / write_file implementation and convert users
to it where (easily) possible.

Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230203003947.38033-2-bgray@linux.ibm.com
This commit is contained in:
Benjamin Gray
2023-02-03 11:39:43 +11:00
committed by Michael Ellerman
parent b505063910
commit a974f0c131
7 changed files with 122 additions and 162 deletions

View File

@@ -12,24 +12,13 @@
static int check_cpu_dscr_default(char *file, unsigned long val)
{
char buf[10];
int fd, rc;
char buf[10] = {0};
int rc;
fd = open(file, O_RDWR);
if (fd == -1) {
perror("open() failed");
return 1;
}
rc = read_file(file, buf, sizeof(buf) - 1, NULL);
if (rc)
return rc;
rc = read(fd, buf, sizeof(buf));
if (rc == -1) {
perror("read() failed");
close(fd);
return 1;
}
close(fd);
buf[rc] = '\0';
if (strtol(buf, NULL, 16) != val) {
printf("DSCR match failed: %ld (system) %ld (cpu)\n",
val, strtol(buf, NULL, 16));