Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit test output #131

Merged
merged 3 commits into from
Jan 13, 2025
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
_build
lib/krml
lib/charon
out
test/*/target
out/*/a.out
*.DS_Store
*.orig
*.llbc
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ CHARON ?= $(CHARON_HOME)/bin/charon
BROKEN_TESTS = step_by where_clauses chunks mutable_slice_range closure issue_49 issue_37 issue_105
TEST_DIRS = $(filter-out $(BROKEN_TESTS),$(subst test/,,$(shell find test -maxdepth 1 -mindepth 1 -type d)))

# Enable `foo/**` glob syntax
SHELL := bash -O globstar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nadrieril Son started reporting issues with this:

bash: line 0: globstar: invalid shell option name
bash: line 0: globstar: invalid shell option name

@sonmarcho is possibly on OSX where the default version of make is rather old -- we forbid this in some other projects https://github.com/hacl-star/hacl-star/blob/main/Makefile#L46-L49

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, that looks like a bash difference, not a make difference

Copy link
Member Author

@Nadrieril Nadrieril Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed an OSX difference: https://apple.stackexchange.com/questions/291287/globstar-invalid-shell-option-name-on-macos-even-with-bash-4-x . I guess I should avoid the glob and do a find | xargs dance? I can't believe I can't even rely on having a decently modern bash though :'(.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I meant bash -- this is the same issue, OSX ships a very outdated bash for GPLv3 reasons

this is the bash version that is bad in OSX:

jonathan@absinthe:~/Code/noise-star/src (main) $ /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin24)

if you can detect that and error out with a suggestion to brew install bash, then I'm fine with it (I personally run with brew bash and everyone else should)

jonathan@absinthe:~/Code/noise-star/src (main) $ /bin/bash
bash: complete: nosort: invalid option name

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
jonathan@absinthe:~/Code/noise-star/src (main) $ echo $BASH_VERSION
3.2.57(1)-release

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know a reliable way to detect that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since Apple's bash is frozen in time I think it's ok to check for that exact version string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know how to do such a check in a makefile? I'd rather not run it on every test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do something like

SHELL=/bin/env bash
_ := $(shell bash -c '(( ${BASH_VERSION%%.*} >= 4 ))')
ifneq ($(.SHELLSTATUS),0)
_: $(error "bash version too old")
endif

(sketch)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need to use $$ though to prevent make from attempting variable expansion

SED=$(shell which gsed &>/dev/null && echo gsed || echo sed)

.PHONY: all
all: format-check
@ocamlfind list | grep -q charon || test -L lib/charon || echo "⚠️⚠️⚠️ Charon not found; we suggest cd lib && ln -s path/to/charon charon"
Expand Down Expand Up @@ -36,6 +40,8 @@ test-symcrust: CFLAGS += -Wno-unused-function

test-%: test/%/out.llbc out/test-%/main.c | all
$(EURYDICE) $(EXTRA) --output out/test-$* $<
$(SED) -i 's/ KaRaMeL version: .*//' out/test-$*/**/*.{c,h} # This changes on every commit
$(SED) -i 's/ KaRaMeL invocation: .*//' out/test-$*/**/*.{c,h} # This changes between local and CI
cd out/test-$* && $(CC) $(CFLAGS) -I. -I../../include $(EXTRA_C) $*.c main.c && ./a.out

custom-test-array: test-array
Expand Down
18 changes: 18 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,31 @@
buildInputs = [ charon.buildInputs eurydice ];
nativeBuildInputs = [ charon.nativeBuildInputs clang ];
buildPhase = ''
shopt -s globstar
export CHARON="${charon}/bin/charon"

# setup CHARON_HOME: it is expected to be writtable, hence the `cp --no-preserve`
cp --no-preserve=mode,ownership -rf ${inputs.charon.sourceInfo.outPath} ./charon
export CHARON_HOME=./charon

# Move the committed test outputs out of the way
mv out out-comitted

# Run the tests
make -o all test

# Clean generated files that we don't want to compare.
rm out/**/a.out
Nadrieril marked this conversation as resolved.
Show resolved Hide resolved

# Check that there are no differences between the generated
# outputs and the committed outputs.
if diff -rq out-comitted out; then
echo "Ok: the regenerated files are the same as the checked out files"
else
echo "Error: the regenerated files differ from the checked out files"
diff -ru out-comitted out
exit 1
fi
'';
installPhase = ''touch $out'';
};
Expand Down
112 changes: 112 additions & 0 deletions out/test-array/array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
This file was generated by KaRaMeL <https://github.com/FStarLang/karamel>

F* version: <unknown>

*/

#include "array.h"

array_Foo array_mk_foo(void)
{
uint32_t x[2U] = { 0U };
uint32_t y[2U] = { 1U, 1U };
/* Passing arrays by value in Rust generates a copy in C */
uint32_t copy_of_x[2U];
memcpy(copy_of_x, x, (size_t)2U * sizeof (uint32_t));
/* Passing arrays by value in Rust generates a copy in C */
uint32_t copy_of_y[2U];
memcpy(copy_of_y, y, (size_t)2U * sizeof (uint32_t));
array_Foo lit;
memcpy(lit.x, copy_of_x, (size_t)2U * sizeof (uint32_t));
memcpy(lit.y, copy_of_y, (size_t)2U * sizeof (uint32_t));
return lit;
}

array_Foo array_mk_foo2(void)
{
return array_mk_foo();
}

void array_mut_array(uint32_t x[2U])
{
x[0U] = 1U;
}

void array_mut_foo(array_Foo f)
{
f.x[0U] = 1U;
uint32_t copy[2U];
memcpy(copy, f.y, (size_t)2U * sizeof (uint32_t));
copy[0U] = 0U;
}

/**
A monomorphic instance of array.mk_incr.closure
with const generics
- K= 10
*/
uint32_t array_mk_incr_closure_95(size_t i)
{
return (uint32_t)i;
}

/**
A monomorphic instance of array.mk_incr
with const generics
- K= 10
*/
void array_mk_incr_95(uint32_t ret[10U])
{
KRML_MAYBE_FOR10(i, (size_t)0U, (size_t)10U, (size_t)1U, ret[i] = (uint32_t)i;);
}

typedef struct _uint32_t__x2_s
{
uint32_t *fst;
uint32_t *snd;
}
_uint32_t__x2;

void array_main(void)
{
/* XXX1 */
array_Foo uu____0 = array_mk_foo2();
uint32_t x[2U];
memcpy(x, uu____0.x, (size_t)2U * sizeof (uint32_t));
uint32_t y[2U];
memcpy(y, uu____0.y, (size_t)2U * sizeof (uint32_t));
uint32_t unsigned0 = 0U;
uint32_t uu____1[2U];
memcpy(uu____1, x, (size_t)2U * sizeof (uint32_t));
array_mut_array(uu____1);
/* Passing arrays by value in Rust generates a copy in C */
uint32_t copy_of_x[2U];
/* XXX2 */
memcpy(copy_of_x, x, (size_t)2U * sizeof (uint32_t));
/* Passing arrays by value in Rust generates a copy in C */
uint32_t copy_of_y[2U];
memcpy(copy_of_y, y, (size_t)2U * sizeof (uint32_t));
array_Foo lit;
memcpy(lit.x, copy_of_x, (size_t)2U * sizeof (uint32_t));
memcpy(lit.y, copy_of_y, (size_t)2U * sizeof (uint32_t));
array_mut_foo(lit);
_uint32_t__x2 uu____4;
uu____4.fst = x;
uu____4.snd = &unsigned0;
/* XXX3 */
uint32_t *left_val = uu____4.fst;
uint32_t *right_val0 = uu____4.snd;
EURYDICE_ASSERT(left_val[0U] == right_val0[0U], "panic!");
uint32_t a[10U];
array_mk_incr_95(a);
_uint32_t__x2 uu____5;
uu____5.fst = &a[9U];
/* original Rust expression is not an lvalue in C */
uint32_t lvalue = 9U;
uu____5.snd = &lvalue;
uint32_t *left_val0 = uu____5.fst;
uint32_t *right_val = uu____5.snd;
EURYDICE_ASSERT(left_val0[0U] == right_val[0U], "panic!");
}

59 changes: 59 additions & 0 deletions out/test-array/array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
This file was generated by KaRaMeL <https://github.com/FStarLang/karamel>

F* version: <unknown>

*/

#ifndef __array_H
#define __array_H

#if defined(__cplusplus)
extern "C" {
#endif

#include "eurydice_glue.h"

typedef struct array_Foo_s
{
uint32_t x[2U];
uint32_t y[2U];
}
array_Foo;

#define core_panicking_AssertKind_Eq 0
#define core_panicking_AssertKind_Ne 1
#define core_panicking_AssertKind_Match 2

typedef uint8_t core_panicking_AssertKind;

array_Foo array_mk_foo(void);

array_Foo array_mk_foo2(void);

void array_mut_array(uint32_t x[2U]);

void array_mut_foo(array_Foo f);

/**
A monomorphic instance of array.mk_incr.closure
with const generics
- K= 10
*/
uint32_t array_mk_incr_closure_95(size_t i);

/**
A monomorphic instance of array.mk_incr
with const generics
- K= 10
*/
void array_mk_incr_95(uint32_t ret[10U]);

void array_main(void);

#if defined(__cplusplus)
}
#endif

#define __array_H_DEFINED
#endif
54 changes: 54 additions & 0 deletions out/test-array2d/array2d.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
This file was generated by KaRaMeL <https://github.com/FStarLang/karamel>

F* version: <unknown>

*/

#include "array2d.h"

bool array2d_f(uint32_t x[4U][2U])
{
x[0U][0U] = 1U;
x[0U][1U] = 2U;
uint32_t y[4U][2U] = { { 1U, 2U }, { 3U, 4U }, { 1U, 2U }, { 3U, 4U } };
return
core_array_equality___core__cmp__PartialEq__Array_U__N___for__Array_T__N____eq((size_t)4U,
x,
y,
uint32_t [2U],
uint32_t [2U],
bool);
}

typedef struct _bool__x2_s
{
bool *fst;
bool *snd;
}
_bool__x2;

void array2d_main(void)
{
uint32_t y[4U][2U];
KRML_MAYBE_FOR4(i,
(size_t)0U,
(size_t)4U,
(size_t)1U,
y[i][0U] = 1U;
y[i][1U] = 2U;);
y[1U][0U] = 3U;
y[1U][1U] = 4U;
y[3U][0U] = 3U;
y[3U][1U] = 4U;
/* Passing arrays by value in Rust generates a copy in C */
uint32_t copy_of_y[4U][2U];
memcpy(copy_of_y, y, (size_t)4U * sizeof (uint32_t [2U]));
bool actual = array2d_f(copy_of_y);
bool expected = true;
_bool__x2 uu____1 = { .fst = &actual, .snd = &expected };
bool *left_val = uu____1.fst;
bool *right_val = uu____1.snd;
EURYDICE_ASSERT(left_val[0U] == right_val[0U], "panic!");
}

38 changes: 38 additions & 0 deletions out/test-array2d/array2d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
This file was generated by KaRaMeL <https://github.com/FStarLang/karamel>

F* version: <unknown>

*/

#ifndef __array2d_H
#define __array2d_H

#if defined(__cplusplus)
extern "C" {
#endif

#include "eurydice_glue.h"

bool array2d_f(uint32_t x[4U][2U]);

#define core_panicking_AssertKind_Eq 0
#define core_panicking_AssertKind_Ne 1
#define core_panicking_AssertKind_Match 2

typedef uint8_t core_panicking_AssertKind;

void array2d_main(void);

extern bool
core_cmp_impls___core__cmp__PartialEq_u32__for_u32__24__eq(uint32_t *x0, uint32_t *x1);

extern bool
core_cmp_impls___core__cmp__PartialEq_u32__for_u32__24__ne(uint32_t *x0, uint32_t *x1);

#if defined(__cplusplus)
}
#endif

#define __array2d_H_DEFINED
#endif
36 changes: 36 additions & 0 deletions out/test-const_generics/Eurydice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
This file was generated by KaRaMeL <https://github.com/FStarLang/karamel>

F* version: <unknown>

*/

#ifndef __Eurydice_H
#define __Eurydice_H

#if defined(__cplusplus)
extern "C" {
#endif

#include "eurydice_glue.h"

/**
A monomorphic instance of core.ops.range.RangeTo
with types size_t

*/
typedef size_t core_ops_range_RangeTo_08;

/**
A monomorphic instance of core.ops.range.RangeFrom
with types size_t

*/
typedef size_t core_ops_range_RangeFrom_08;

#if defined(__cplusplus)
}
#endif

#define __Eurydice_H_DEFINED
#endif
Loading