Skip to content

Commit

Permalink
Repair tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phischu committed Feb 6, 2025
1 parent b843c27 commit e70680d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
12 changes: 6 additions & 6 deletions examples/benchmarks/input_output/interleave_promises.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def run(n: Int) = {
promise(box {
with on[IOError].result
val filename = foldername ++ i.show ++ ".txt"
val file = open(filename, WriteOnly())
val file = openForWriting(filename)
val buffer = bytearray(size, 35.toByte)
repeat(8) {
val i = write(file, buffer, 0, size, -1)
if (i < size) {
val m = write(file, buffer, 0, size, -1)
if (m < buffer.size) {
panic("failed write")
}
}
Expand All @@ -38,11 +38,11 @@ def run(n: Int) = {
promises.foreachIndex { (i, p) =>
p.await().value()
val filename = foldername ++ i.show ++ ".txt"
val file = open(filename, ReadOnly())
val file = openForReading(filename)
val buffer = bytearray::allocate(size)
repeat(8) {
val i = read(file, buffer, 0, size, -1)
if (i < size) {
val m = read(file, buffer, 0, size, -1)
if (m < buffer.size) {
panic("failed read")
}
}
Expand Down
23 changes: 14 additions & 9 deletions examples/benchmarks/input_output/large_file.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,38 @@ import io/filesystem


def run(n: Int) = {
with on[IOError].panic;

val filename = "/tmp/large_file.txt"
val size = 4096

val _ = {
val file = open(filename, WriteOnly())
val file = internal::openForWriting(filename)
if (file < 0) {
panic("failed open for writing")
}
val outputBuffer = bytearray(size, 33.toByte)
outputBuffer.unsafeSet(999, 10.toByte)
repeat(n) {
val i = write(file, outputBuffer, 0, size, -1)
if (i < size) {
val m = internal::write(file, outputBuffer, 0, size, -1)
if (m < outputBuffer.size) {
panic("failed write")
}
}
close(file)
internal::close(file)
}

val file = open(filename, ReadOnly())
val file = internal::openForReading(filename)
if (file < 0) {
panic("failed open for reading")
}
val inputBuffer = bytearray::allocate(size)
repeat(n) {
val i = read(file, inputBuffer, 0, size, -1)
if (i < size) {
val m = internal::read(file, inputBuffer, 0, size, -1)
if (m < inputBuffer.size) {
panic("failed read")
}
}
close(file)
internal::close(file)

return 0
}
Expand Down
30 changes: 19 additions & 11 deletions examples/benchmarks/input_output/small_files.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,42 @@ import io/filesystem


def run(n: Int) = {
with on[IOError].panic;

val foldername = "/tmp/small_files/"
val size = 4096

on[IOError].result { mkdir(foldername) } match {
case Error(EEXIST(), msg) => ()
case Error(e, m) => do raise(e, m)
case Success(()) => ()
val code = internal::mkdir(foldername)
if (code < 0 && code != -17) {
panic("failed to make directory")
}

val buffer = bytearray(size, 33.toByte)
each(0, n) { i =>
val filename = foldername ++ i.show ++ ".txt"
val file = open(filename, WriteOnly())
if (write(file, buffer, 0, size, -1) < size) {
val file = internal::openForWriting(filename)
if (file < 0) {
panic("failed open for writing")
}
val m = internal::write(file, buffer, 0, size, -1)
if (m < buffer.size) {
panic("failed write")
}
close(file)
val _ = internal::close(file)
()
}

each(0, n) { i =>
val filename = foldername ++ i.show ++ ".txt"
val file = open(filename, ReadOnly())
if (read(file, buffer, 0, size, -1) < size) {
val file = internal::openForReading(filename)
if (file < 0) {
panic("failed open for reading")
}
val m = internal::read(file, buffer, 0, size, -1)
if (m < buffer.size) {
panic("failed read")
}
close(file)
val _ = internal::close(file)
()
}

return 0
Expand Down
4 changes: 2 additions & 2 deletions libraries/llvm/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void c_fs_open(String path, int flags, Stack stack) {
uv_fs_t* request = malloc(sizeof(uv_fs_t));
request->data = stack;

int result = uv_fs_open(uv_default_loop(), request, path_str, flags, 0666, c_resume_int_fs);
int result = uv_fs_open(uv_default_loop(), request, path_str, flags, 0777, c_resume_int_fs);

if (result < 0) {
uv_fs_req_cleanup(request);
Expand Down Expand Up @@ -157,7 +157,7 @@ void c_fs_mkdir(String path, Stack stack) {
request->data = stack;

// Perform the mkdir operation
int result = uv_fs_mkdir(uv_default_loop(), request, path_str, 0666, c_resume_int_fs);
int result = uv_fs_mkdir(uv_default_loop(), request, path_str, 0777, c_resume_int_fs);

if (result < 0) {
uv_fs_req_cleanup(request);
Expand Down

0 comments on commit e70680d

Please sign in to comment.