Skip to content

Commit

Permalink
Merge pull request #31 from brenhinkeller/readtest
Browse files Browse the repository at this point in the history
Readtest
  • Loading branch information
brenhinkeller authored Nov 2, 2022
2 parents cf07595 + 8a884a2 commit cc5a8a9
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.8.0-beta3'
- '1.8'
os:
- macos-latest
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.8.0-beta3'
- '1.8'
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StaticTools"
uuid = "86c06d3c-3f03-46de-9781-57580aa96d0a"
authors = ["C. Brenhin Keller and contributors"]
version = "0.8.0"
version = "0.8.1"

[deps]
ManualMemory = "d125e4d3-2237-4719-b19c-fa641b8a4667"
Expand Down
46 changes: 46 additions & 0 deletions test/scripts/readwrite.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using StaticCompiler
using StaticTools

function readwrite(argc::Int, argv::Ptr{Ptr{UInt8}})
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
rows = argparse(Int64, argv, 2) # First command-line argument
cols = argparse(Int64, argv, 3) # Second command-line argument

M = MallocArray{Int64}(undef, rows, cols)
@inbounds for i=1:rows
for j=1:cols
M[i,j] = i*j
end
end
# Print to file
fwrite(c"table.b", M)
printdlm(c"table.tsv", M)


Mb = read(c"table.b", MallocArray{Int64})
Mbv = ArrayView{Int64,2}(pointer(Mb), rows*cols, (rows, cols))
printdlm(c"tableb.tsv", Mbv)
printf(Mbv)

Ms = read(c"table.b", MallocString)
Msv = ArrayView{Int64,2}(pointer(Ms), rows*cols, (rows, cols))
printdlm(c"tables.tsv", Msv)
printf(Msv)

Mts = read(c"table.tsv", MallocString)
fwrite(c"tablets.tsv", Mts)
printf(Mts)

# Mt = parsedlm(Int64, c"table.tsv")

# match = M == Mb == Mbv == Msv

# Clean up
free(M), free(Mb), free(Ms), free(Mts)

# return !match % Int32
return Int32(0)
end

# Attempt to compile
path = compile_executable(readwrite, (Int64, Ptr{Ptr{UInt8}}), "./")
37 changes: 37 additions & 0 deletions test/teststaticcompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,43 @@ let
@test fread!(szeros(Int, 5,5), c"table.b") == (1:5)*(1:5)'
end

## --- Reading from written files

let
# Compile...
status = -1
try
isfile("readwrite") && rm("readwrite")
status = run(`$jlpath --compile=min $testpath/scripts/readwrite.jl`)
catch e
@warn "Could not compile $testpath/scripts/readwrite.jl"
println(e)
end
@test isa(status, Base.Process)
@test isa(status, Base.Process) && status.exitcode == 0

# Run...
println("5x5 times table, read from file:")
status = -1
try
status = run(`./readwrite 5 5`)
catch e
@warn "Could not run $(scratch)/readwrite"
println(e)
end
@test isa(status, Base.Process)
@test isa(status, Base.Process) && status.exitcode == 0
# Test binary output
@test fread!(szeros(Int, 5,5), c"table.b") == (1:5)*(1:5)'
# Test ascii output
@test parsedlm(Int, c"table.tsv", '\t') == (1:5)*(1:5)'
@test parsedlm(Int, c"tableb.tsv", '\t') == (1:5)*(1:5)'
@test parsedlm(Int, c"tables.tsv", '\t') == (1:5)*(1:5)'
@test parsedlm(Int, c"tablets.tsv", '\t') == (1:5)*(1:5)'

end


## --- "withmallocarray"-type do-block pattern
let
# Compile...
Expand Down

0 comments on commit cc5a8a9

Please sign in to comment.