[PATCH] selftests: Add tests for efivarfs
This change adds a few initial efivarfs tests to the tools/testing/selftests directory. The open-unlink test is based on code from Lingzhu Xiang lxi...@redhat.com. Signed-off-by: Jeremy Kerr jeremy.k...@canonical.com CC: linux-efi@vger.kernel.org CC: Lingzhu Xiang lxi...@redhat.com CC: Matt Fleming m...@console-pimps.org --- tools/testing/selftests/Makefile |2 tools/testing/selftests/efivarfs/Makefile | 12 + tools/testing/selftests/efivarfs/efivarfs.sh | 127 + tools/testing/selftests/efivarfs/open-unlink.c | 60 4 files changed, 200 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 85baf11..dee19dd 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -1,4 +1,4 @@ -TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug +TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug efivarfs all: for TARGET in $(TARGETS); do \ diff --git a/tools/testing/selftests/efivarfs/Makefile b/tools/testing/selftests/efivarfs/Makefile new file mode 100644 index 000..1a943ee --- /dev/null +++ b/tools/testing/selftests/efivarfs/Makefile @@ -0,0 +1,12 @@ +CC = $(CROSS_COMPILE)gcc +CFLAGS = -Wall + +test_objs = open-unlink + +all: $(test_objs) + +run_tests: all + @./efivarfs.sh || echo efivarfs selftests: [FAIL] + +clean: + rm -f $(test_objs) diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh b/tools/testing/selftests/efivarfs/efivarfs.sh new file mode 100755 index 000..5abd55e --- /dev/null +++ b/tools/testing/selftests/efivarfs/efivarfs.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +efivarfs_mount=/sys/firmware/efi/efivars +test_guid=210be57c-9849-4fc7-a635-e6382d1aec27 + +check_prereqs() +{ + local msg=skip all tests: + + if [ $UID != 0 ]; then + echo $msg must be run as root 2 + exit 0 + fi + + if ! grep -q ^\S\+ $efivarfs_mount efivarfs /proc/mounts; then + echo $msg efivarfs is not mounted on $efivarfs_mount 2 + exit 0 + fi + + # the open-unlink test relies on deleting the Lang variable at + # present; we don't want to do this on an actual machine. + if ! grep -q 'model name.* QEMU' /proc/cpuinfo; then + echo $msg efivarfs tests should only be run on a VM 2 + exit 0 + fi + +} + +run_test() +{ + local test=$1 + + echo + echo running $test + echo + + if [ $(type -t $test) = 'function' ]; then + ( $test ) + else + ( ./$test ) + fi + + if [ $? -ne 0 ]; then + echo [FAIL] + rc=1 + else + echo [PASS] + fi +} + +test_create() +{ + local attrs='\x07\x00\x00\x00' + local file=$efivarfs_mount/test.1-$test_guid + + printf $attrs\x00 $file + + if [ ! -e $file ]; then + echo $file couldn't be created 2 + exit 1 + fi + + if [ $(stat -c %s $file) -ne 5 ]; then + echo $file has invalid size 2 + exit 1 + fi +} + +test_delete() +{ + local attrs='\x07\x00\x00\x00' + local file=$efivarfs_mount/test.2-$test_guid + + printf $attrs\x00 $file + + if [ ! -e $file ]; then + echo $file couldn't be created 2 + exit 1 + fi + + rm $file + + if [ -e $file ]; then + echo $file couldn't be deleted 2 + exit 1 + fi + +} + +# test that we can remove a variable by issuing a write with only +# attributes specified +test_zero_size_delete() +{ + local attrs='\x07\x00\x00\x00' + local file=$efivarfs_mount/test.3-$test_guid + + printf $attrs\x00 $file + + if [ ! -e $file ]; then + echo $file does not exist 2 + exit 1 + fi + + printf $attrs $file + + if [ -e $file ]; then + echo $file should have been deleted 2 + exit 1 + fi +} + +test_open_unlink() +{ + local file=$efivarfs_mount/test.4-$test_guid + ./open-unlink $file +} + +check_prereqs + +rc=0 + +run_test test_create +run_test test_delete +run_test test_zero_size_delete +run_test test_open_unlink + +exit $rc diff --git a/tools/testing/selftests/efivarfs/open-unlink.c b/tools/testing/selftests/efivarfs/open-unlink.c new file mode 100644 index 000..fd2a542 --- /dev/null +++ b/tools/testing/selftests/efivarfs/open-unlink.c @@ -0,0 +1,60 @@ +#include stdio.h +#include stdint.h +#include stdlib.h +#include unistd.h +#include sys/types.h +#include sys/stat.h +#include fcntl.h + +int main(int argc, char **argv) +{ + const char *path; + char buf[5]; + int fd, rc; + + if (argc 2) { + fprintf(stderr, usage: %s path\n, argv[0]); +
[GIT PULL] EFI fixes for v3.8
Hi Peter, The following changes since commit 7d1f9aeff1ee4a20b1aeb377dd0f579fe9647619: Linux 3.8-rc4 (2013-01-17 19:25:45 -0800) are available in the git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git tags/efi-for-3.8 for you to fetch changes up to 791eb564d218dabe0f9a2212916fe54240b97afb: efivarfs: Delete dentry from dcache in efivarfs_file_write() (2013-01-18 09:43:44 +) EFI fixes for v3.8 * Fix EFI boot crash on machines with 512GB of RAM * Fix a few oopses in efivarfs Lingzhu Xiang (1): efivarfs: Drop link count of the right inode Matt Fleming (2): efivarfs: Never return ENOENT from firmware efivarfs: Delete dentry from dcache in efivarfs_file_write() Nathan Zimmer (1): efi, x86: Pass a proper identity mapping in efi_call_phys_prelog arch/x86/platform/efi/efi_64.c | 22 +- drivers/firmware/efivars.c | 5 +++-- 2 files changed, 20 insertions(+), 7 deletions(-) -- Matt Fleming, Intel Open Source Technology Center -- To unsubscribe from this list: send the line unsubscribe linux-efi in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2] fix setup_efi_pci()
This fixes two issues: - wrong memory type used for allocation intended to persist post-boot - four similar build warnings on 32-bit (casts between different size pointers and integers) Signed-off-by: Jan Beulich jbeul...@suse.com --- v2: Drop the change that was already applied separately (commit 886d751a2ea99a160f2d0a472231566d9cb0cf58 x86, efi: correct precedence of operators in setup_efi_pci) --- arch/x86/boot/compressed/eboot.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) --- 3.8-rc4/arch/x86/boot/compressed/eboot.c +++ 3.8-rc4-x86-EFI-PCI-ROMs/arch/x86/boot/compressed/eboot.c @@ -256,10 +256,10 @@ static efi_status_t setup_efi_pci(struct int i; struct setup_data *data; - data = (struct setup_data *)params-hdr.setup_data; + data = (struct setup_data *)(unsigned long)params-hdr.setup_data; while (data data-next) - data = (struct setup_data *)data-next; + data = (struct setup_data *)(unsigned long)data-next; status = efi_call_phys5(sys_table-boottime-locate_handle, EFI_LOCATE_BY_PROTOCOL, pci_proto, @@ -311,7 +311,7 @@ static efi_status_t setup_efi_pci(struct size = pci-romsize + sizeof(*rom); status = efi_call_phys3(sys_table-boottime-allocate_pool, - EFI_LOADER_DATA, size, rom); + EFI_RUNTIME_SERVICES_DATA, size, rom); if (status != EFI_SUCCESS) continue; @@ -345,9 +345,9 @@ static efi_status_t setup_efi_pci(struct memcpy(rom-romdata, pci-romimage, pci-romsize); if (data) - data-next = (uint64_t)rom; + data-next = (unsigned long)rom; else - params-hdr.setup_data = (uint64_t)rom; + params-hdr.setup_data = (unsigned long)rom; data = (struct setup_data *)rom; -- To unsubscribe from this list: send the line unsubscribe linux-efi in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [GIT PULL] EFI fixes for v3.8
On Fri, 2013-01-18 at 10:29 +, Matt Fleming wrote: Hi Peter, The following changes since commit 7d1f9aeff1ee4a20b1aeb377dd0f579fe9647619: Linux 3.8-rc4 (2013-01-17 19:25:45 -0800) are available in the git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git tags/efi-for-3.8 for you to fetch changes up to 791eb564d218dabe0f9a2212916fe54240b97afb: efivarfs: Delete dentry from dcache in efivarfs_file_write() (2013-01-18 09:43:44 +) EFI fixes for v3.8 * Fix EFI boot crash on machines with 512GB of RAM * Fix a few oopses in efivarfs I believe the EFI boot stub is still totally hosed on 32-bit, and doesn't correctly set up the graphics when running under qemu in either mode. Any chance of merging those fixes for 3.8 too? I probably should have marked them for stable, too. Not to mention the fact that no sane bootloader can *use* the EFI boot stub until we start indicating which mode it needs to be invoked in... which could probably *also* go to stable, in fact. It's just a couple of new flags in the existing loadflags fields, and doesn't really even need the bootproto version to be bumped. -- dwmw2 smime.p7s Description: S/MIME cryptographic signature