Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
341 changes: 333 additions & 8 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"rpc_protocol",
"tests/alloc",
"tests/no_alloc",
"tests/zcopy",
"xdr_codegen",
"xdr_lib",
]
11 changes: 11 additions & 0 deletions tests/zcopy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "test_zcopy"
version = "0.1.0"
edition = "2021"

[build-dependencies]
xdr_codegen = { path = "../../xdr_codegen" }

[dependencies]
xdr_lib = { path = "../../xdr_lib" }
rand = "0.10.1"
12 changes: 12 additions & 0 deletions tests/zcopy/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn main() {
xdr_codegen::Compiler::new()
.file("input/arrays.x")
.file("input/hello.x")
.file("input/typedef.x")
.file("input/unions.x")
.file("input/structs.x")
.file("input/optional.x")
.enable_zcopy()
.run()
.expect("That should have worked. :(");
}
44 changes: 44 additions & 0 deletions tests/zcopy/input/arrays.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
struct OpaqueArrays {
opaque bytes[3];
opaque bytes_2<3>;
opaque bytes_3<>;
};

struct AnInt {
unsigned int a;
};

struct IntArrays {
AnInt fixed[4];
AnInt limited<7>;
AnInt unlimited<>;
};

struct Strings {
string str<7>;
string str_2<>;
};

struct ManyStrings {
Strings first;
Strings many[4];
Strings last;
};

const AMOUNT = 5;
struct IdentifierArray {
opaque bytes[AMOUNT];
string str<AMOUNT>;
int ints<AMOUNT>;
};

struct ManyInts {
unsigned hyper first[2];
int second<7>;
hyper third<>;
};

struct ConstSizeArray {
opaque bytes[AMOUNT];
int ints[AMOUNT];
};
14 changes: 14 additions & 0 deletions tests/zcopy/input/hello.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enum Fruit {
Apple = 1,
Banana = 2,
StarFruit = 3
};

struct Hello {
unsigned int abc;
int def;
Fruit favorite_fruit;
};

const A_CONSTANT = 12345;
const another = 15;
44 changes: 44 additions & 0 deletions tests/zcopy/input/optional.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
struct ListNode {
int data;
ListNode *next;
};

struct ListBegin {
ListNode *list;
};

struct NonRecursive {
int stuff;
string str<>;
};

struct JustAnOption {
NonRecursive *maybe;
};

/* Example optional types from mount protocol: */

const MNTPATHLEN = 1024; /* Maximum bytes in a path name */
const MNTNAMLEN = 255; /* Maximum bytes in a name */
const FHSIZE3 = 64; /* Maximum bytes in a V3 file handle */

typedef opaque fhandle3<FHSIZE3>;
typedef string dirpath<MNTPATHLEN>;
typedef string name<MNTNAMLEN>;

typedef struct groupnode *groups;

struct groupnode {
name gr_name;
groups gr_next;
};

struct exports {
exportnode *inner;
};

struct exportnode {
dirpath ex_dir;
groups ex_groups;
exportnode *ex_next;
};
25 changes: 25 additions & 0 deletions tests/zcopy/input/structs.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
enum Val {
one = 1,
two = 2,
three = 3
};

struct Another {
Val val;
hyper x;
unsigned hyper y;
};

struct Bar {
unsigned int a;
Another one;
int b;
};

struct Foo {
int a;
Bar blah;
unsigned int b;
bool no;
bool yes;
};
18 changes: 18 additions & 0 deletions tests/zcopy/input/typedef.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
typedef int uid;
typedef string filename<>;
typedef opaque data<1024>;

struct TimestampsData {
int atime;
int ctime;
int mtime;
};

typedef TimestampsData Timestamps;

struct File {
uid owner;
filename name;
data contents;
Timestamps t;
};
89 changes: 89 additions & 0 deletions tests/zcopy/input/unions.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
enum PlantKind {
Tree = 0,
Grass = 1,
Flower = 2
};

union Plant switch (PlantKind kind) {
case Tree:
int num_branches;
case Grass:
int num_seeds;
case Flower:
int num_petals;
};

union NumLeaves switch (bool is_plant) {
case TRUE:
unsigned int leaves;
default:
void;
};

union MaybeAPlantKind switch (bool yes) {
case TRUE:
PlantKind plant_kind;
case FALSE:
void;
};

struct Stuff {
int a;
unsigned hyper b;
};

union MaybeStuff switch (bool yes) {
case TRUE:
Stuff things;
case FALSE:
void;
};

union HasString switch (bool yes) {
case TRUE:
string str<>;
case FALSE:
void;
};

enum Cases {
one = 1,
two = 2,
three = 3,
four = 4
};

union StuffOrPlant switch (Cases hello) {
case one:
Stuff things;
case two:
PlantKind plant_kind;
case three:
Plant plant;
};

struct SameWidthDifferentStuff {
int a;
int b;
int c;
};

union StuffOrPlant2 switch (Cases hello) {
case one:
Stuff things;
case two:
SameWidthDifferentStuff differentThings;
case three:
Stuff sameThings;
case four:
int hi;
default:
Cases dead;
};

struct HasUnion {
StuffOrPlant a;
StuffOrPlant2 b;
NumLeaves c;
Plant nocache;
};
Loading
Loading