void Make_sure_all_Code_values_are_tested_exactly_once() { var tested = new bool[IcedConstants.CodeEnumCount]; foreach (var info in OpCodeInfoTestCases.OpCodeInfoTests) { Assert.False(tested[(int)info.Code]); tested[(int)info.Code] = true; } var sb = new StringBuilder(); var codeNames = ToEnumConverter.GetCodeNames(); for (int i = 0; i < tested.Length; i++) { if (!tested[i] && !CodeUtils.IsIgnored(codeNames[i])) { if (sb.Length > 0) { sb.Append(','); } sb.Append(codeNames[i]); } } Assert.Equal(string.Empty, sb.ToString()); }
void Verify_encoding_is_part_of_Code_name() { var codeNames = ToEnumConverter.GetCodeNames(); for (int i = 0; i < IcedConstants.NumberOfCodeValues; i++) { var codeName = codeNames[i]; if (CodeUtils.IsIgnored(codeName)) { continue; } var code = (Code)i; var prefix = code.ToOpCode().Encoding switch { EncodingKind.Legacy => string.Empty, EncodingKind.VEX => "VEX_", EncodingKind.EVEX => "EVEX_", EncodingKind.XOP => "XOP_", EncodingKind.D3NOW => "D3NOW_", _ => throw new InvalidOperationException(), }; if (prefix != string.Empty) { Assert.StartsWith(prefix, codeName, StringComparison.Ordinal); } } }
void Make_sure_all_Code_values_are_tested() { var tested = new bool[IcedConstants.NumberOfCodeValues]; foreach (var info in GetTests()) { tested[(int)(Code)info[1]] = true; } var sb = new StringBuilder(); int missing = 0; var codeNames = ToEnumConverter.GetCodeNames().ToArray(); Assert.Equal(tested.Length, codeNames.Length); for (int i = 0; i < tested.Length; i++) { if (!tested[i]) { sb.Append(codeNames[i] + " "); missing++; } } Assert.Equal("0 ins ", $"{missing} ins " + sb.ToString()); }
void Make_sure_all_Code_values_are_tested_in_16_32_64_bit_modes() { const byte T16 = 0x01; const byte T32 = 0x02; const byte T64 = 0x04; var tested = new byte[IcedConstants.NumberOfCodeValues]; tested[(int)Code.INVALID] = T16 | T32 | T64; foreach (var info in DecoderTestUtils.GetDecoderTests(includeOtherTests: false, includeInvalid: false)) { Assert.False(DecoderTestUtils.NotDecoded.Contains(info.Code), $"{info.Code} has a decoder test but it shouldn't be decoded"); tested[(int)info.Code] |= info.Bitness switch { 16 => T16, 32 => T32, 64 => T64, _ => throw new InvalidOperationException(), }; } #if ENCODER foreach (var info in NonDecodedInstructions.GetTests()) { tested[(int)info.instruction.Code] |= info.bitness switch { 16 => T16, 32 => T32, 64 => T64, _ => throw new InvalidOperationException(), }; } #else foreach (var code in NonDecodedCodeValues1632) { tested[(int)code] |= T16 | T32; } foreach (var code in NonDecodedCodeValues) { tested[(int)code] |= T16 | T32 | T64; } #endif foreach (var c in DecoderTestUtils.NotDecoded) { Assert.DoesNotContain(c, DecoderTestUtils.Code32Only); Assert.DoesNotContain(c, DecoderTestUtils.Code64Only); } foreach (var c in DecoderTestUtils.NotDecoded32Only) { tested[(int)c] ^= T64; } foreach (var c in DecoderTestUtils.NotDecoded64Only) { tested[(int)c] ^= T16 | T32; } foreach (var c in DecoderTestUtils.Code32Only) { Assert.DoesNotContain(c, DecoderTestUtils.Code64Only); tested[(int)c] ^= T64; } foreach (var c in DecoderTestUtils.Code64Only) { Assert.DoesNotContain(c, DecoderTestUtils.Code32Only); tested[(int)c] ^= T16 | T32; } var sb16 = new StringBuilder(); var sb32 = new StringBuilder(); var sb64 = new StringBuilder(); int missing16 = 0, missing32 = 0, missing64 = 0; var codeNames = ToEnumConverter.GetCodeNames(); Assert.Equal(tested.Length, codeNames.Length); for (int i = 0; i < tested.Length; i++) { if (tested[i] != (T16 | T32 | T64) && !CodeUtils.IsIgnored(codeNames[i])) { if ((tested[i] & T16) == 0) { sb16.Append(codeNames[i] + " "); missing16++; } if ((tested[i] & T32) == 0) { sb32.Append(codeNames[i] + " "); missing32++; } if ((tested[i] & T64) == 0) { sb64.Append(codeNames[i] + " "); missing64++; } } } Assert.Equal("16: 0 ins ", $"16: {missing16} ins " + sb16.ToString()); Assert.Equal("32: 0 ins ", $"32: {missing32} ins " + sb32.ToString()); Assert.Equal("64: 0 ins ", $"64: {missing64} ins " + sb64.ToString()); }