|
19 | 19 | #include <linux/random.h> |
20 | 20 | #include <sound/cs-amp-lib.h> |
21 | 21 |
|
| 22 | +#define LENOVO_SPEAKER_ID_EFI_NAME L"SdwSpeaker" |
| 23 | +#define LENOVO_SPEAKER_ID_EFI_GUID \ |
| 24 | + EFI_GUID(0x48df970e, 0xe27f, 0x460a, 0xb5, 0x86, 0x77, 0x19, 0x80, 0x1d, 0x92, 0x82) |
| 25 | + |
| 26 | +#define HP_SPEAKER_ID_EFI_NAME L"HPSpeakerID" |
| 27 | +#define HP_SPEAKER_ID_EFI_GUID \ |
| 28 | + EFI_GUID(0xc49593a4, 0xd099, 0x419b, 0xa2, 0xc3, 0x67, 0xe9, 0x80, 0xe6, 0x1d, 0x1e) |
| 29 | + |
22 | 30 | KUNIT_DEFINE_ACTION_WRAPPER(faux_device_destroy_wrapper, faux_device_destroy, |
23 | 31 | struct faux_device *) |
24 | 32 |
|
@@ -642,6 +650,185 @@ static void cs_amp_lib_test_write_cal_data_test(struct kunit *test) |
642 | 650 | KUNIT_EXPECT_EQ(test, entry->value, data.calStatus); |
643 | 651 | } |
644 | 652 |
|
| 653 | +static void cs_amp_lib_test_spkid_lenovo_not_present(struct kunit *test) |
| 654 | +{ |
| 655 | + struct cs_amp_lib_test_priv *priv = test->priv; |
| 656 | + struct device *dev = &priv->amp_dev->dev; |
| 657 | + |
| 658 | + kunit_activate_static_stub(test, |
| 659 | + cs_amp_test_hooks->get_efi_variable, |
| 660 | + cs_amp_lib_test_get_efi_variable_none); |
| 661 | + |
| 662 | + KUNIT_EXPECT_EQ(test, -ENOENT, cs_amp_get_vendor_spkid(dev)); |
| 663 | +} |
| 664 | + |
| 665 | +static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d0(efi_char16_t *name, |
| 666 | + efi_guid_t *guid, |
| 667 | + unsigned long *size, |
| 668 | + void *buf) |
| 669 | +{ |
| 670 | + struct kunit *test = kunit_get_current_test(); |
| 671 | + |
| 672 | + if (efi_guidcmp(*guid, LENOVO_SPEAKER_ID_EFI_GUID) || |
| 673 | + memcmp(name, LENOVO_SPEAKER_ID_EFI_NAME, sizeof(LENOVO_SPEAKER_ID_EFI_NAME))) |
| 674 | + return EFI_NOT_FOUND; |
| 675 | + |
| 676 | + KUNIT_ASSERT_EQ(test, *size, 1); |
| 677 | + *size = 1; |
| 678 | + *(u8 *)buf = 0xd0; |
| 679 | + |
| 680 | + return EFI_SUCCESS; |
| 681 | +} |
| 682 | + |
| 683 | +static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d1(efi_char16_t *name, |
| 684 | + efi_guid_t *guid, |
| 685 | + unsigned long *size, |
| 686 | + void *buf) |
| 687 | +{ |
| 688 | + struct kunit *test = kunit_get_current_test(); |
| 689 | + |
| 690 | + if (efi_guidcmp(*guid, LENOVO_SPEAKER_ID_EFI_GUID) || |
| 691 | + memcmp(name, LENOVO_SPEAKER_ID_EFI_NAME, sizeof(LENOVO_SPEAKER_ID_EFI_NAME))) |
| 692 | + return EFI_NOT_FOUND; |
| 693 | + |
| 694 | + KUNIT_ASSERT_EQ(test, *size, 1); |
| 695 | + *size = 1; |
| 696 | + *(u8 *)buf = 0xd1; |
| 697 | + |
| 698 | + return EFI_SUCCESS; |
| 699 | +} |
| 700 | + |
| 701 | +static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_00(efi_char16_t *name, |
| 702 | + efi_guid_t *guid, |
| 703 | + unsigned long *size, |
| 704 | + void *buf) |
| 705 | +{ |
| 706 | + struct kunit *test = kunit_get_current_test(); |
| 707 | + |
| 708 | + KUNIT_ASSERT_EQ(test, 0, efi_guidcmp(*guid, LENOVO_SPEAKER_ID_EFI_GUID)); |
| 709 | + KUNIT_ASSERT_EQ(test, *size, 1); |
| 710 | + *size = 1; |
| 711 | + *(u8 *)buf = 0; |
| 712 | + |
| 713 | + return EFI_SUCCESS; |
| 714 | +} |
| 715 | + |
| 716 | +static void cs_amp_lib_test_spkid_lenovo_d0(struct kunit *test) |
| 717 | +{ |
| 718 | + struct cs_amp_lib_test_priv *priv = test->priv; |
| 719 | + struct device *dev = &priv->amp_dev->dev; |
| 720 | + |
| 721 | + kunit_activate_static_stub(test, |
| 722 | + cs_amp_test_hooks->get_efi_variable, |
| 723 | + cs_amp_lib_test_get_efi_variable_lenovo_d0); |
| 724 | + |
| 725 | + KUNIT_EXPECT_EQ(test, 0, cs_amp_get_vendor_spkid(dev)); |
| 726 | +} |
| 727 | + |
| 728 | +static void cs_amp_lib_test_spkid_lenovo_d1(struct kunit *test) |
| 729 | +{ |
| 730 | + struct cs_amp_lib_test_priv *priv = test->priv; |
| 731 | + struct device *dev = &priv->amp_dev->dev; |
| 732 | + |
| 733 | + kunit_activate_static_stub(test, |
| 734 | + cs_amp_test_hooks->get_efi_variable, |
| 735 | + cs_amp_lib_test_get_efi_variable_lenovo_d1); |
| 736 | + |
| 737 | + KUNIT_EXPECT_EQ(test, 1, cs_amp_get_vendor_spkid(dev)); |
| 738 | +} |
| 739 | + |
| 740 | +static void cs_amp_lib_test_spkid_lenovo_illegal(struct kunit *test) |
| 741 | +{ |
| 742 | + struct cs_amp_lib_test_priv *priv = test->priv; |
| 743 | + struct device *dev = &priv->amp_dev->dev; |
| 744 | + |
| 745 | + kunit_activate_static_stub(test, |
| 746 | + cs_amp_test_hooks->get_efi_variable, |
| 747 | + cs_amp_lib_test_get_efi_variable_lenovo_00); |
| 748 | + |
| 749 | + KUNIT_EXPECT_LT(test, cs_amp_get_vendor_spkid(dev), 0); |
| 750 | +} |
| 751 | + |
| 752 | +static efi_status_t cs_amp_lib_test_get_efi_variable_buf_too_small(efi_char16_t *name, |
| 753 | + efi_guid_t *guid, |
| 754 | + unsigned long *size, |
| 755 | + void *buf) |
| 756 | +{ |
| 757 | + return EFI_BUFFER_TOO_SMALL; |
| 758 | +} |
| 759 | + |
| 760 | +static void cs_amp_lib_test_spkid_lenovo_oversize(struct kunit *test) |
| 761 | +{ |
| 762 | + struct cs_amp_lib_test_priv *priv = test->priv; |
| 763 | + struct device *dev = &priv->amp_dev->dev; |
| 764 | + |
| 765 | + kunit_activate_static_stub(test, |
| 766 | + cs_amp_test_hooks->get_efi_variable, |
| 767 | + cs_amp_lib_test_get_efi_variable_buf_too_small); |
| 768 | + |
| 769 | + KUNIT_EXPECT_LT(test, cs_amp_get_vendor_spkid(dev), 0); |
| 770 | +} |
| 771 | + |
| 772 | +static efi_status_t cs_amp_lib_test_get_efi_variable_hp_30(efi_char16_t *name, |
| 773 | + efi_guid_t *guid, |
| 774 | + unsigned long *size, |
| 775 | + void *buf) |
| 776 | +{ |
| 777 | + struct kunit *test = kunit_get_current_test(); |
| 778 | + |
| 779 | + if (efi_guidcmp(*guid, HP_SPEAKER_ID_EFI_GUID) || |
| 780 | + memcmp(name, HP_SPEAKER_ID_EFI_NAME, sizeof(HP_SPEAKER_ID_EFI_NAME))) |
| 781 | + return EFI_NOT_FOUND; |
| 782 | + |
| 783 | + KUNIT_ASSERT_EQ(test, *size, 1); |
| 784 | + *size = 1; |
| 785 | + *(u8 *)buf = 0x30; |
| 786 | + |
| 787 | + return EFI_SUCCESS; |
| 788 | +} |
| 789 | + |
| 790 | +static efi_status_t cs_amp_lib_test_get_efi_variable_hp_31(efi_char16_t *name, |
| 791 | + efi_guid_t *guid, |
| 792 | + unsigned long *size, |
| 793 | + void *buf) |
| 794 | +{ |
| 795 | + struct kunit *test = kunit_get_current_test(); |
| 796 | + |
| 797 | + if (efi_guidcmp(*guid, HP_SPEAKER_ID_EFI_GUID) || |
| 798 | + memcmp(name, HP_SPEAKER_ID_EFI_NAME, sizeof(HP_SPEAKER_ID_EFI_NAME))) |
| 799 | + return EFI_NOT_FOUND; |
| 800 | + |
| 801 | + KUNIT_ASSERT_EQ(test, *size, 1); |
| 802 | + *size = 1; |
| 803 | + *(u8 *)buf = 0x31; |
| 804 | + |
| 805 | + return EFI_SUCCESS; |
| 806 | +} |
| 807 | + |
| 808 | +static void cs_amp_lib_test_spkid_hp_30(struct kunit *test) |
| 809 | +{ |
| 810 | + struct cs_amp_lib_test_priv *priv = test->priv; |
| 811 | + struct device *dev = &priv->amp_dev->dev; |
| 812 | + |
| 813 | + kunit_activate_static_stub(test, |
| 814 | + cs_amp_test_hooks->get_efi_variable, |
| 815 | + cs_amp_lib_test_get_efi_variable_hp_30); |
| 816 | + |
| 817 | + KUNIT_EXPECT_EQ(test, 0, cs_amp_get_vendor_spkid(dev)); |
| 818 | +} |
| 819 | + |
| 820 | +static void cs_amp_lib_test_spkid_hp_31(struct kunit *test) |
| 821 | +{ |
| 822 | + struct cs_amp_lib_test_priv *priv = test->priv; |
| 823 | + struct device *dev = &priv->amp_dev->dev; |
| 824 | + |
| 825 | + kunit_activate_static_stub(test, |
| 826 | + cs_amp_test_hooks->get_efi_variable, |
| 827 | + cs_amp_lib_test_get_efi_variable_hp_31); |
| 828 | + |
| 829 | + KUNIT_EXPECT_EQ(test, 1, cs_amp_get_vendor_spkid(dev)); |
| 830 | +} |
| 831 | + |
645 | 832 | static int cs_amp_lib_test_case_init(struct kunit *test) |
646 | 833 | { |
647 | 834 | struct cs_amp_lib_test_priv *priv; |
@@ -737,6 +924,15 @@ static struct kunit_case cs_amp_lib_test_cases[] = { |
737 | 924 | /* Tests for writing calibration data */ |
738 | 925 | KUNIT_CASE(cs_amp_lib_test_write_cal_data_test), |
739 | 926 |
|
| 927 | + /* Test cases for speaker ID */ |
| 928 | + KUNIT_CASE(cs_amp_lib_test_spkid_lenovo_not_present), |
| 929 | + KUNIT_CASE(cs_amp_lib_test_spkid_lenovo_d0), |
| 930 | + KUNIT_CASE(cs_amp_lib_test_spkid_lenovo_d1), |
| 931 | + KUNIT_CASE(cs_amp_lib_test_spkid_lenovo_illegal), |
| 932 | + KUNIT_CASE(cs_amp_lib_test_spkid_lenovo_oversize), |
| 933 | + KUNIT_CASE(cs_amp_lib_test_spkid_hp_30), |
| 934 | + KUNIT_CASE(cs_amp_lib_test_spkid_hp_31), |
| 935 | + |
740 | 936 | { } /* terminator */ |
741 | 937 | }; |
742 | 938 |
|
|
0 commit comments