Permalink
Browse files

endian_switch01: rewrite to newlib

Also check that syscall is supported (doesn't return ENOSYS),
before running actual test. This is to address kernels where
this syscall is disabled by default:
  commit 727f13616c45 ("powerpc: Disable the fast-endian switch syscall by default")

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Acked-by: Cyril Hrubis <chrubis@suse.cz>
Tested-by: Li Wang <liwang@redhat.com>
  • Loading branch information...
jstancek committed Jan 10, 2018
1 parent 16990f5 commit 68fb61225d4ae943eb7c7f621c1424d0d586b5ed
Showing with 96 additions and 113 deletions.
  1. +96 −113 testcases/kernel/syscalls/switch/endian_switch01.c
@@ -1,142 +1,125 @@
/******************************************************************************/
/* */
/* Copyright (c) International Business Machines Corp., 2008 */
/* Copyright 2008 Paul Mackerras, IBM Corp. */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
/* the GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* File: endian_switch01.c */
/* */
/* Description: Test little-endian mode switch system call. Requires a 64-bit */
/* processor that supports little-endian mode,such as POWER6. */
/* */
/* Total Tests: 1 */
/* */
/* Test Name: endian_switch01 */
/* */
/* Author: Paul Mackerras <paulus@samba.org> */
/* */
/* History: Created - Sep 02 2008 - Paul Mackerras <paulus@samba.org> */
/* Ported to LTP */
/* - Sep 02 2008 */
/* - Subrata Modak <subrata@linux.vnet.ibm.com> */
/* */
/******************************************************************************/
/*
* Copyright (c) International Business Machines Corp., 2008
* Copyright (c) Paul Mackerras, IBM Corp., 2008
* Copyright (c) 2018 Linux Test Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Test little-endian mode switch system call. Requires a 64-bit
* processor that supports little-endian mode,such as POWER6.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <elf.h>
#include <signal.h>
#include <setjmp.h>
#include "test.h"
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <fcntl.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "lapi/syscalls.h"
#if defined (__powerpc64__) || (__powerpc__)
static void setup();
#endif
static void cleanup();
char *TCID = "endian_switch01";
int TST_TOTAL = 1;
#include <elf.h>
#include "tst_test.h"
#if defined (__powerpc64__) || (__powerpc__)
void setup(void)
# ifndef PPC_FEATURE_TRUE_LE
# define PPC_FEATURE_TRUE_LE 0x00000002
# endif
# define TST_NO_DEFAULT_MAIN
/*
* Make minimal call to 0x1ebe. If we get ENOSYS then syscall is not
* available, likely because of:
* commit 727f13616c45 ("powerpc: Disable the fast-endian switch syscall by default")
* If we get any other outcome, including crashes with various signals,
* then we assume syscall is available and carry on with the test.
*/
void check_le_switch_supported(void)
{
int status;
tst_sig(FORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
}
if (SAFE_FORK() == 0) {
syscall(0x1ebe);
exit(errno);
}
extern int main4(int ac, char **av, char **envp, unsigned long *auxv)
__asm("main");
#endif
SAFE_WAIT(&status);
if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
void cleanup(void)
{
tst_res(TINFO, "check exited with sig %d", sig);
} else if (WIFEXITED(status)) {
int rc = WEXITSTATUS(status);
tst_res(TINFO, "check exited with %d", rc);
if (rc == ENOSYS)
tst_brk(TCONF, "fast endian switch (0x1ebe) N/A");
}
}
#if defined (__powerpc64__) || (__powerpc__)
#ifndef PPC_FEATURE_TRUE_LE
#define PPC_FEATURE_TRUE_LE 0x00000002
#endif
void test_le_switch(void)
{
int status;
#include <asm/cputable.h>
if (SAFE_FORK() == 0) {
register int r0 asm("r0") = 0x1ebe;
volatile int got_sigill;
sigjmp_buf jb;
asm volatile ("sc; .long 0x02000044"
: "=&r" (r0)
: "0"(r0)
: "cr0", "r9", "r10", "r11", "r12");
exit(0);
}
void sigill(int sig)
{
got_sigill = 1;
siglongjmp(jb, 1);
}
SAFE_WAIT(&status);
if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
void do_le_switch(void)
{
register int r0 asm("r0");
tst_res(TFAIL, "test exited with sig %d", sig);
} else if (WIFEXITED(status)) {
int rc = WEXITSTATUS(status);
r0 = 0x1ebe;
asm volatile ("sc; .long 0x02000044":"=&r" (r0):"0"(r0)
:"cr0", "r9", "r10", "r11", "r12");
if (rc != 0)
tst_res(TFAIL, "test exited with %d", rc);
else
tst_res(TPASS, "endian_switch() syscall tests passed");
}
}
int main4(int ac, char **av, char **envp, unsigned long *auxv)
static void endian_test(void)
{
if ((tst_kvercmp(2, 6, 26)) < 0) {
tst_brkm(TCONF,
NULL,
"This test can only run on kernels that are 2.6.26 and higher");
}
setup();
for (; *auxv != AT_NULL && *auxv != AT_HWCAP; auxv += 2) ;
if (!(auxv[0] == AT_HWCAP && (auxv[1] & PPC_FEATURE_TRUE_LE))) {
tst_brkm(TCONF, cleanup,
"Processor does not support little-endian mode");
}
signal(SIGILL, sigill);
if (sigsetjmp(jb, 1) == 0)
do_le_switch();
if (got_sigill) {
tst_brkm(TFAIL, NULL, "Got SIGILL - test failed");
}
tst_resm(TPASS, "endian_switch() syscall tests passed");
tst_exit();
check_le_switch_supported();
test_le_switch();
}
#else
static struct tst_test test = {
.test_all = endian_test,
.min_kver = "2.6.26",
.forks_child = 1,
};
int main(void)
int main4(int argc, char **argv, LTP_ATTRIBUTE_UNUSED char **envp,
unsigned long *auxv)
{
for (; *auxv != AT_NULL && *auxv != AT_HWCAP; auxv += 2)
;
if (!(auxv[0] == AT_HWCAP && (auxv[1] & PPC_FEATURE_TRUE_LE)))
tst_brk(TCONF, "Processor does not support little-endian mode");
tst_brkm(TCONF, cleanup,
"This system does not support running of switch() syscall");
tst_run_tcases(argc, argv, &test);
return 0;
}
#else /* defined (__powerpc64__) || (__powerpc__) */
TST_TEST_TCONF("This system does not support running of switch() syscall");
#endif

0 comments on commit 68fb612

Please sign in to comment.