Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <fcntl.h> |
| 18 | #include <unistd.h> |
| 19 | |
| 20 | #include "hf/dlog.h" |
| 21 | |
| 22 | #include "hftest.h" |
| 23 | #include <sys/syscall.h> |
| 24 | |
| 25 | static int finit_module(int fd, const char *param_values, int flags) |
| 26 | { |
| 27 | return syscall(SYS_finit_module, fd, param_values, flags); |
| 28 | } |
| 29 | |
| 30 | static int delete_module(const char *name, int flags) |
| 31 | { |
| 32 | return syscall(SYS_delete_module, name, flags); |
| 33 | } |
| 34 | |
| 35 | static void insmod_hafnium(void) |
| 36 | { |
| 37 | int module_file = open("/hafnium.ko", O_RDONLY); |
| 38 | if (module_file < 0) { |
| 39 | FAIL("Failed to load Hafnium kernel module from /hafnium.ko"); |
| 40 | return; |
| 41 | } |
| 42 | EXPECT_EQ(finit_module(module_file, "", 0), 0); |
| 43 | close(module_file); |
| 44 | } |
| 45 | |
| 46 | static void rmmod_hafnium(void) |
| 47 | { |
| 48 | EXPECT_EQ(delete_module("hafnium", 0), 0); |
| 49 | } |
| 50 | |
| 51 | TEST(linux, load_hafnium) |
| 52 | { |
| 53 | insmod_hafnium(); |
| 54 | rmmod_hafnium(); |
| 55 | } |