xref: /third_party/ltp/testcases/kernel/mce-test/tsrc/tsoft.c (revision f08c3bdf)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/ltp/testcases/kernel/mce-test/tsrc/
1f08c3bdfSopenharmony_ci/* Simplest soft offline testcase */
2f08c3bdfSopenharmony_ci#include <stdlib.h>
3f08c3bdfSopenharmony_ci#include <sys/mman.h>
4f08c3bdfSopenharmony_ci#include <stdio.h>
5f08c3bdfSopenharmony_ci#include <unistd.h>
6f08c3bdfSopenharmony_ci
7f08c3bdfSopenharmony_ci#define err(x) perror(x), exit(1)
8f08c3bdfSopenharmony_ci
9f08c3bdfSopenharmony_ci#define MADV_SOFT_OFFLINE 101          /* soft offline page for testing */
10f08c3bdfSopenharmony_ci
11f08c3bdfSopenharmony_ciint PS;
12f08c3bdfSopenharmony_ci
13f08c3bdfSopenharmony_ciint main(void)
14f08c3bdfSopenharmony_ci{
15f08c3bdfSopenharmony_ci	PS = getpagesize();
16f08c3bdfSopenharmony_ci	char *map = mmap(NULL, PS,  PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
17f08c3bdfSopenharmony_ci
18f08c3bdfSopenharmony_ci	if (map == (char *)-1L)
19f08c3bdfSopenharmony_ci		err("mmap");
20f08c3bdfSopenharmony_ci
21f08c3bdfSopenharmony_ci	*map = 1;
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_ci	if (madvise(map, PS, MADV_SOFT_OFFLINE) < 0)
24f08c3bdfSopenharmony_ci		perror("madvise SOFT_OFFLINE");
25f08c3bdfSopenharmony_ci
26f08c3bdfSopenharmony_ci	*map = 2;
27f08c3bdfSopenharmony_ci
28f08c3bdfSopenharmony_ci	return 0;
29f08c3bdfSopenharmony_ci}
30

Indexes created Thu Nov 07 10:32:03 CST 2024