interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / tests / native / v2 / host / hcall.c

39 lines · 1640 bytes Raw Blame History
1/* hcall.c: the C oracle for hfile.om through the --host library (tests/native/v2/run.sh, section 11).
2 * hcall FILE MISSING LINK: FILE holds 5 bytes, MISSING does not exist, LINK is a symlink to FILE.
3 * Each expectation is computed here by libc, independently of the Omega unit. */
4#define _GNU_SOURCE
5#include <errno.h>
6#include <stdint.h>
7#include <stdio.h>
8#include <string.h>
9#include <sys/stat.h>
10#include <unistd.h>
11#include "omega_native.h"
12
13static int bad;
14static void check(const char *what, int ok) {
15 printf("%s %s\n", ok ? "PASS" : "FAIL", what);
16 if (!ok) bad = 1;
17}
18
19static int64_t peek(const char *p) {
20 uint64_t r = 0;
21 if (omega2_peek(&r, (const uint8_t *)p, strlen(p)) != OMEGA_OK) return INT64_MIN;
22 return (int64_t)r;
23}
24
25int main(int argc, char **argv) {
26 if (argc != 4) { fprintf(stderr, "usage: hcall FILE MISSING LINK\n"); return 2; }
27 uint64_t r = 0;
28 uint64_t want = (uint64_t)getuid() + geteuid() + getgid() + getegid();
29 check("ids == getuid+geteuid+getgid+getegid", omega2_ids(&r) == OMEGA_OK && r == want);
30 check("peek FILE reads its 5 bytes", peek(argv[1]) == 5);
31 check("peek MISSING = -ENOENT", peek(argv[2]) == -ENOENT);
32 check("peek LINK = -ELOOP (fopen with O_NOFOLLOW)", peek(argv[3]) == -ELOOP);
33 struct stat st;
34 check("size FILE == st_size", stat(argv[1], &st) == 0 && omega2_size(&r, (const uint8_t *)argv[1], strlen(argv[1])) == OMEGA_OK
35 && (int64_t)r == (int64_t)st.st_size);
36 check("ident carries host=", strstr(omega2_ident_hfile(), " host=") != NULL
37 && strcmp(omega2_ident_hfile(), OMEGA2_IDENT_hfile) == 0);
38 return bad;
39}