| 1 | namespace Zipelo.StreamProtocolTests; |
| 2 | |
| 3 | internal static class Program |
| 4 | { |
| 5 | private static readonly (string Name, Func<Task> Run)[] Cases = |
| 6 | [ |
| 7 | ("wire.empty_job", () => ChannelTests.RoundTrip([])), |
| 8 | ("wire.empty_item", () => ChannelTests.RoundTrip([0])), |
| 9 | ("wire.one_byte", () => ChannelTests.RoundTrip([1])), |
| 10 | ("wire.chunk_boundaries", () => ChannelTests.RoundTrip([65535, 65536])), |
| 11 | ("wire.fragmented_reads", () => ChannelTests.RoundTrip([1, 7, 1024], 3)), |
| 12 | ("wire.golden_64_byte_header", () => ChannelTests.GoldenHeader()), |
| 13 | ("wire.all_header_truncations", () => ChannelTests.TruncatedHeaders()), |
| 14 | ("wire.metadata_and_data_truncations", () => ChannelTests.TruncatedBodies()), |
| 15 | ("wire.magic_version_reserved", () => ChannelTests.FixedFields()), |
| 16 | ("wire.kind_length_and_uint_overflow", () => ChannelTests.KindsAndLengths()), |
| 17 | ("wire.huge_declaration_allocation_bound", () => ChannelTests.HugeDeclarations()), |
| 18 | ("state.job_and_item_ids", () => ValidatorTests.Identifiers()), |
| 19 | ("state.sequence_duplicate_gap_overflow", () => ValidatorTests.Sequences()), |
| 20 | ("state.missing_and_nested_transitions", () => ValidatorTests.Transitions()), |
| 21 | ("state.duplicate_item_id", () => ValidatorTests.DuplicateItem()), |
| 22 | ("state.actual_declared_end_lengths", () => ValidatorTests.ItemLengths()), |
| 23 | ("state.status_and_open_item", () => ValidatorTests.TerminalStatus()), |
| 24 | ("state.failed_cancelled_eof", () => ChannelTests.FailedTerminals()), |
| 25 | ("state.eof_before_terminal", () => ChannelTests.EarlyEof()), |
| 26 | ("state.trailing_byte_duplicate_end", () => ChannelTests.TrailingData()), |
| 27 | ("state.terminal_without_eof_deadline", () => ChannelTests.MissingEof()), |
| 28 | ("state.final_status_over_cancel_and_deadline", () => ChannelTests.FinalStatePriority()), |
| 29 | ("budget.invalid_limits", () => ValidatorTests.Limits()), |
| 30 | ("budget.validate_header_does_not_spend", () => ValidatorTests.HeaderValidationDoesNotSpend()), |
| 31 | ("budget.wire_exact_and_one_short", () => ValidatorTests.WireBudget()), |
| 32 | ("budget.data_cumulative_16mib", () => ValidatorTests.DataBudget()), |
| 33 | ("budget.small_chunk_frame_count", () => ValidatorTests.FrameBudget()), |
| 34 | ("budget.empty_item_count", () => ValidatorTests.ItemBudget()), |
| 35 | ("budget.signed_and_payload_lengths", () => ValidatorTests.ArithmeticLengths()), |
| 36 | ("cancel.before_io", () => ChannelTests.PreCancelled()), |
| 37 | ("cancel.read_header", () => ChannelTests.BlockedRead(false, false)), |
| 38 | ("cancel.read_body", () => ChannelTests.BlockedRead(true, false)), |
| 39 | ("cancel.write_header", () => ChannelTests.BlockedWrite("header", false)), |
| 40 | ("cancel.write_body", () => ChannelTests.BlockedWrite("body", false)), |
| 41 | ("cancel.write_flush", () => ChannelTests.BlockedWrite("flush", false)), |
| 42 | ("deadline.read_wait", () => ChannelTests.BlockedRead(true, true)), |
| 43 | ("deadline.write_wait", () => ChannelTests.BlockedWrite("body", true)), |
| 44 | ("deadline.between_calls", () => ChannelTests.BetweenCallsDeadline()), |
| 45 | ("flow.slow_producer", () => ChannelTests.BlockedRead(true, false, true)), |
| 46 | ("flow.slow_consumer_snapshot", () => ChannelTests.BlockedWrite("body", false, true)), |
| 47 | ("flow.flush_completion", () => ChannelTests.BlockedWrite("flush", false, true)), |
| 48 | ("fault.read_io_and_reuse", () => ChannelTests.IoFailure(true)), |
| 49 | ("fault.write_io_and_reuse", () => ChannelTests.IoFailure(false)), |
| 50 | ("api.concurrent_call_and_dispose", () => ChannelTests.ConcurrentCalls()), |
| 51 | ("api.direction_stream_lifetime", () => ChannelTests.DirectionAndLifetime()), |
| 52 | ("api.invalid_write_before_output", () => ChannelTests.InvalidWrite()), |
| 53 | ]; |
| 54 | |
| 55 | public static async Task<int> Main(string[] arguments) |
| 56 | { |
| 57 | if (arguments is ["--list"]) |
| 58 | { |
| 59 | foreach (var item in Cases) { Console.WriteLine(item.Name); } |
| 60 | Console.WriteLine($"등록: {Cases.Length}"); |
| 61 | return 0; |
| 62 | } |
| 63 | if (arguments.Length != 0) { return 2; } |
| 64 | var passed = 0; |
| 65 | var failed = 0; |
| 66 | foreach (var (name, run) in Cases) |
| 67 | { |
| 68 | try |
| 69 | { |
| 70 | await run().WaitAsync(TimeSpan.FromSeconds(8)); |
| 71 | Console.WriteLine($"PASS {name}"); |
| 72 | passed++; |
| 73 | } |
| 74 | catch (TimeoutException) |
| 75 | { |
| 76 | Console.Error.WriteLine($"FAIL {name}: 검사 제한 시간 초과"); |
| 77 | Console.WriteLine($"등록 {Cases.Length}, 통과 {passed}, 실패 {failed + 1}, 미실행 {Cases.Length - passed - failed - 1}"); |
| 78 | return 124; |
| 79 | } |
| 80 | catch (Exception exception) |
| 81 | { |
| 82 | Console.Error.WriteLine($"FAIL {name}: {exception.GetType().Name}: {exception.Message}"); |
| 83 | failed++; |
| 84 | } |
| 85 | } |
| 86 | Console.WriteLine($"등록 {Cases.Length}, 통과 {passed}, 실패 {failed}, SKIP 0"); |
| 87 | return failed == 0 ? 0 : 1; |
| 88 | } |
| 89 | } |