Skip to content

Commit

Permalink
ltp/kernel: add compat implementation for compiling ltp kernel cases
Browse files Browse the repository at this point in the history
Signed-off-by: guoshichao <[email protected]>
  • Loading branch information
extinguish committed Dec 24, 2024
1 parent aba32a5 commit b3d4c81
Show file tree
Hide file tree
Showing 30 changed files with 847 additions and 0 deletions.
24 changes: 24 additions & 0 deletions nuttx/asm/posix_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* asm/posix_types.h */

#ifndef _ASM_POSIX_TYPES_H
#define _ASM_POSIX_TYPES_H

/* This is just a placeholder to simplify cross-compiling the LTP Linux Kernel cases */

#endif /* _ASM_POSIX_TYPES_H */
24 changes: 24 additions & 0 deletions nuttx/asm/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* asm/types.h */

#ifndef _ASM_TYPES_H
#define _ASM_TYPES_H

#include <sys/types.h>

#endif /* _ASM_TYPES_H */
125 changes: 125 additions & 0 deletions nuttx/dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <nuttx/config.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <mntent.h>

/* the following implementation build when CONFIG_SYSTEM_POPEN option is disabled.*/

#ifndef CONFIG_SYSTEM_POPEN

FILE *popen(const char *command, const char *mode)
{
return NULL;
}

int pclose(FILE *stream)
{
return OK;
}
#endif

/* the following empty implementation using to compile the LTP Kernel case on nuttx */
int chroot(const char *path)
{
return -1;
}

int setpgid(pid_t pid, pid_t pgid)
{
return -1;
}

FILE *setmntent(const char *filep, const char *type)
{
return NULL;
}

struct mntent *getmntent(FILE *filep)
{
return NULL;
}

struct mntent *getmntent_r(FILE *, struct mntent *, char *, int)
{
return NULL;
}

int endmntent(FILE *filep)
{
return -1;
}

char *hasmntopt(const struct mntent *mnt, const char *opt)
{
return NULL;
}

/* the following are dummy implementation using to compile fsgid related cased on nuttx */

int setfsgid(uid_t fsgid)
{
return -1;
}

int setfsuid(uid_t fsuid)
{
return -1;
}

/* the following syscalls are needed by:
* lib/tst_safe_macros.c
* lib/safe_macros.c
* lib/parse_opts.c
*/
int mincore(void *addr, size_t length, unsigned char *vec)
{
return -1;
}

pid_t setsid(void)
{
return -1;
}

int brk(void *addr)
{
return -1;
}

#ifndef CONFIG_BUILD_KERNEL

void *sbrk(intptr_t increment)
{
return NULL;
}

#endif

int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid)
{
return -1;
}

int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
{
return -1;
}
24 changes: 24 additions & 0 deletions nuttx/features.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* features.h */

#ifndef _FEATURES_H
#define _FEATURES_H

/* This is just a placeholder to simplify cross-compiling the LTP Linux Kernel cases */

#endif /* _FEATURES_H */
38 changes: 38 additions & 0 deletions nuttx/lapi/posix_clocks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* posix_clocks.h */

#ifndef _LAPI_POSIX_CLOCKS_H__
#define _LAPI_POSIX_CLOCKS_H__

#include <time.h>

#define MAX_CLOCKS 16

#define CLOCK_MONOTONIC_RAW 5

#define CLOCK_REALTIME_COARSE 6

#define CLOCK_MONOTONIC_COARSE 7

#define CLOCK_REALTIME_ALARM 8

#define CLOCK_BOOTTIME_ALARM 9

#define CLOCK_TAI 11

#endif /* _LAPI_POSIX_CLOCKS_H__ */
24 changes: 24 additions & 0 deletions nuttx/libaio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* libaio.h */

#ifndef _LIBAIO_H
#define _LIBAIO_H

/* This is just a placeholder to simplify cross-compiling the LTP Linux Kernel cases */

#endif /* _LIBAIO_H */
24 changes: 24 additions & 0 deletions nuttx/linux/errno.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* linux/errno.h */

#ifndef _LINUX_ERRNO_H
#define _LINUX_ERRNO_H

#include <errno.h>

#endif /* _LINUX_ERRNO_H */
24 changes: 24 additions & 0 deletions nuttx/linux/fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* linux/fs.h */

#ifndef _LINUX_FS_H
#define _LINUX_FS_H

#include <nuttx/fs/fs.h>

#endif /* _LINUX_FS_H */
25 changes: 25 additions & 0 deletions nuttx/linux/futex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* linux/futex.h */

#ifndef _LINUX_FUTEX_H
#define _LINUX_FUTEX_H

#define FUTEX_WAIT 1
#define FUTEX_WAKE 2

#endif /* _LINUX_FUTEX_H */
24 changes: 24 additions & 0 deletions nuttx/linux/if_tun.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* linux/if_tun.h */

#ifndef _LINUX_IF_TUN_H
#define _LINUX_IF_TUN_H

/* This is just a placeholder to simplify cross-compiling the LTP Linux Kernel cases */

#endif /* _LINUX_IF_TUN_H */
24 changes: 24 additions & 0 deletions nuttx/linux/kernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* linux/kernel.h */

#ifndef _LINUX_KERNEL_H
#define _LINUX_KERNEL_H

#include <sys/sysmacros.h>

#endif /* _LINUX_KERNEL_H */
Loading

0 comments on commit b3d4c81

Please sign in to comment.