Files
swift-mirror/test/SILOptimizer/unit_test.sil
Nate Chandler e9ab3b4b53 [Test] Refactored SIL "unit" tests.
Renamed UnitTest to FunctionTest.

FunctionTests are now instantiated once as global objects--with their
names and the code they are to run--at which time they are stored by
name in a global registry.

Moved the types to the SIL library.

Together, these changes enable defining unit tests in the source file
containing the code to be tested.
2023-07-04 11:52:11 -07:00

190 lines
8.7 KiB
Plaintext

// RUN: %target-sil-opt -test-runner %s 2>&1 | %FileCheck %s
sil_stage raw
import Builtin
// CHECK-LABEL: begin running test 1 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK: test_arg_parsing_reference
// CHECK: test_arg_parsing_referenceable
// CHECK: test_arg_parsing
// CHECK: bool: 1
// CHECK: bool: 0
// CHECK-LABEL: end running test 1 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 2 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK: block:
// CHECK: bb0:
// CHECK: function_ref @something_remarkable
// CHECK: uint: 42
// CHECK: instruction: {{%[^,]+}} = tuple ({{%[^,]+}}, {{%[^,]+}}, {{%[^,]+}})
// CHECK-LABEL: end running test 2 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 3 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK: function: test_arg_parsing
// CHECK: function: test_arg_parsing
// CHECK-LABEL: end running test 3 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 4 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK: block:
// CHECK: function_ref @something_remarkable
// CHECK: block:
// CHECK: function_ref @something_remarkable
// CHECK: block:
// CHECK: function_ref @something_remarkable
// CHECK: block:
// CHECK: function_ref @something_remarkable
// CHECK: block:
// CHECK: function_ref @something_remarkable
// CHECK-LABEL: end running test 4 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 5 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK: instruction: // function_ref something_remarkable
// CHECK: instruction: // function_ref something_remarkable
// CHECK: instruction: // function_ref something_remarkable
// CHECK: instruction: // function_ref something_remarkable
// CHECK: instruction: // function_ref something_remarkable
// CHECK: instruction: // function_ref something_remarkable
// CHECK: instruction: // function_ref something_remarkable
// CHECK: instruction: // function_ref something_remarkable
// CHECK-LABEL: end running test 5 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 6 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK: operand:
// CHECK: Owner: return {{%[^,]+}} : $()
// CHECK: operand:
// CHECK: Value: {{%[^,]+}} = tuple ({{%[^,]+}} : $())
// CHECK-LABEL: end running test 6 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 7 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK: value: {{%[^,]+}} = tuple ({{%[^,]+}} : $(), {{%[^,]+}} : $(_: ()), {{%[^,]+}} : $((), (_: ())))
// CHECK: string: howdy
// CHECK-LABEL: end running test 7 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 8 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
// CHECK: value:
// CHECK: function_ref @something_remarkable
// CHECK-LABEL: end running test 8 of {{[^,]+}} on test_arg_parsing: test-specification-parsing
sil [ossa] @test_arg_parsing : $() -> () {
entry:
test_specification "test-specification-parsing FFFbb @function[test_arg_parsing_reference] @function[2] @function true false"
test_specification "test-specification-parsing BuI @block[0] 42 @function[test_arg_parsing_callee].block[1].instruction[3]"
test_specification "test-specification-parsing FF @function @function[0]"
test_specification "test-specification-parsing BBBBB @block @function.block @function.block[0] @function[0].block @function[0].block[0]"
test_specification "test-specification-parsing IIIIIIII @function.block.instruction @function[0].block.instruction @function.block[0].instruction @function.block.instruction[0] @function[0].block[0].instruction @function[0].block.instruction[0] @function.block[0].instruction[0] @function[0].block[0].instruction[0]"
test_specification "test-specification-parsing OO @instruction[2].operand @function[test_arg_parsing_callee].trace.operand[1]"
test_specification "test-specification-parsing Vs @function[4].trace[0] howdy"
test_specification "test-specification-parsing V @instruction[0]"
%something_remarkable = function_ref @something_remarkable : $@convention(thin) () -> ()
%retval = tuple ()
return %retval : $()
}
sil [ossa] @test_arg_parsing_reference : $() -> ()
sil [ossa] @test_arg_parsing_referenceable : $() -> ()
sil [ossa] @something_remarkable : $() -> ()
sil [ossa] @test_arg_parsing_callee : $() -> () {
bb0:
br bb1
bb1:
%zero = tuple ()
%one = tuple (%zero : $())
%two = tuple (%zero : $(), %one : $(_ : ()))
%three = tuple (%zero : $(), %one : $(_ : ()), %two : $((), (_ : ())))
debug_value [trace] %three : $(_ : (), (_ : ()), ((), (_ : ())))
return %zero : $()
}
// CHECK-LABEL: begin running test 1 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
// CHECK: block:
// CHECK: bb1
// CHECK-LABEL: end running test 1 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 2 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
// CHECK: instruction:
// CHECK: tuple
// CHECK-LABEL: end running test 2 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 3 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
// CHECK: instruction: br bb2
// CHECK: instruction: {{%[^,]+}} = tuple ()
// CHECK: instruction: br bb3
// CHECK: instruction: return
// CHECK-LABEL: end running test 3 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 4 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
// CHECK: block
// CHECK: bb0
// CHECK: block
// CHECK: bb1
// CHECK: block
// CHECK: bb2
// CHECK: block
// CHECK: bb3
// CHECK-LABEL: end running test 4 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
// CHECK-LABEL: begin running test 5 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
// CHECK: function: test_contextual_arg_parsing
// CHECK-LABEL: end running test 5 of {{[^,]+}} on test_contextual_arg_parsing: test-specification-parsing
sil [ossa] @test_contextual_arg_parsing : $() -> () {
entry:
br one
one:
test_specification "test-specification-parsing B @block"
br two
two:
test_specification "test-specification-parsing I @instruction"
test_specification "test-specification-parsing IIII @instruction[-1] @instruction[+0] @instruction[+1] @instruction[+2]"
test_specification "test-specification-parsing BBBB @block[-2] @block[-1] @block[+0] @block[+1]"
%retval = tuple ()
br exit
exit:
test_specification "test-specification-parsing F @function"
return %retval : $()
}
struct X {}
// CHECK-LABEL: begin running test 1 of {{[^,]+}} on test_arg_arg_parsing: test-specification-parsing
// CHECK: argument:
// CHECK: %0 = argument of bb0 : $X
// CHECK: argument:
// CHECK: %0 = argument of bb0 : $X
// CHECK: argument:
// CHECK: %0 = argument of bb0 : $X
// CHECK-LABEL: end running test 1 of {{[^,]+}} on test_arg_arg_parsing: test-specification-parsing
sil [ossa] @test_arg_arg_parsing : $(X) -> () {
entry(%instance : $X):
test_specification "test-specification-parsing AAA @argument @block.argument @function.argument[0]"
%retval = tuple ()
return %retval : $()
}
class C {}
sil [ossa] @getC : $@convention(thin) () -> @owned C
sil [ossa] @borrowC : $@convention(thin) (@guaranteed C) -> ()
sil [ossa] @takeC : $@convention(thin) (@owned C) -> ()
// CHECK-LABEL: begin running test 1 of 1 on fn: canonicalize-ossa-lifetime with: true, true, true, @trace
// CHECK-LABEL: end running test 1 of 1 on fn: canonicalize-ossa-lifetime with: true, true, true, @trace
sil [ossa] @fn : $@convention(thin) () -> () {
entry:
test_specification "canonicalize-ossa-lifetime true true true @trace"
%getC = function_ref @getC : $@convention(thin) () -> @owned C
%c = apply %getC() : $@convention(thin) () -> @owned C
debug_value [trace] %c : $C
%borrowC = function_ref @borrowC : $@convention(thin) (@guaranteed C) -> ()
apply %borrowC(%c) : $@convention(thin) (@guaranteed C) -> ()
debug_value %c : $C
destroy_value %c : $C
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: begin running test 1 of {{[^,]+}} on test_arg_parsing_2
// CHECK: block:
// CHECK: {{bb[0-9]+}}:
// CHECK: {{%[^,]+}} = tuple ()
// CHECK: return {{%[^,]+}}
// CHECK: uint: 0
// CHECK-LABEL: end running test 1 of {{[^,]+}} on test_arg_parsing_2
sil @test_arg_parsing_2 : $() -> () {
entry:
test_specification "test-specification-parsing Bu @block[1] 0"
br exit
exit:
%retval = tuple ()
return %retval : $()
}