Changeset View
Changeset View
Standalone View
Standalone View
lib/libkvm/tests/kvm_geterr_test.c
Show All 20 Lines | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | |||||
#include <sys/sysctl.h> | |||||
ngie: This doesn't follow style(9).
1. sys/types.h isn't needed if sys/param.h is present.
2. | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <kvm.h> | #include <kvm.h> | ||||
#include <limits.h> | #include <limits.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | rc = kvm_read(kd, nl[X_MAXCPUS].n_value, &mp_maxcpus, | ||||
sizeof(mp_maxcpus)); | sizeof(mp_maxcpus)); | ||||
ATF_REQUIRE_MSG(rc != -1, "kvm_read failed: %s", kvm_geterr(kd)); | ATF_REQUIRE_MSG(rc != -1, "kvm_read failed: %s", kvm_geterr(kd)); | ||||
error_msg = kvm_geterr(kd); | error_msg = kvm_geterr(kd); | ||||
ATF_REQUIRE_MSG(strcmp(error_msg, ALL_IS_WELL) == 0, | ATF_REQUIRE_MSG(strcmp(error_msg, ALL_IS_WELL) == 0, | ||||
"error message changed: %s", error_msg); | "error message changed: %s", error_msg); | ||||
ATF_REQUIRE_MSG(kvm_close(kd) == 0, "kvm_close failed: %s", | ATF_REQUIRE_MSG(kvm_close(kd) == 0, "kvm_close failed: %s", | ||||
strerror(errno)); | strerror(errno)); | ||||
/* sanity check of value read from kvm_read */ | |||||
jhbUnsubmitted Not Done Inline ActionsI think verifying that kvm_Read() is returning the correct value is probably a decent test, and it should work on all platforms (mp_maxcpus is MI after all). I think sticking it in this test is probably a bit dubious though. I know it would require some code duplication, but I think this should be a standalone test of kvm_read rather than part of this test for kvm_geterr. jhb: I think verifying that kvm_Read() is returning the correct value is probably a decent test, and… | |||||
ngieUnsubmitted Not Done Inline Actions@jhb: agreed. ngie: @jhb: agreed. | |||||
alfredoAuthorUnsubmitted Done Inline ActionsSure, I'm going to create a new test for this check. alfredo: Sure, I'm going to create a new test for this check. | |||||
int sysctl_maxcpus; | |||||
size_t len = sizeof(sysctl_maxcpus); | |||||
retcode = sysctlbyname("kern.smp.maxcpus", &sysctl_maxcpus, &len, NULL, 0); | |||||
ATF_REQUIRE_MSG(retcode == 0, "sysctl read failed : %d", retcode); | |||||
ATF_REQUIRE_EQ_MSG(mp_maxcpus, sysctl_maxcpus, | |||||
"sanity check failed: kvm_read returned %d but sysctl maxcpus returned %d", | |||||
mp_maxcpus, sysctl_maxcpus); | |||||
} | } | ||||
#endif | #endif | ||||
ATF_TP_ADD_TCS(tp) | ATF_TP_ADD_TCS(tp) | ||||
{ | { | ||||
ATF_TP_ADD_TC(tp, kvm_geterr_negative_test_NULL); | ATF_TP_ADD_TC(tp, kvm_geterr_negative_test_NULL); | ||||
#if __FreeBSD_version >= 1100091 | #if __FreeBSD_version >= 1100091 | ||||
ATF_TP_ADD_TC(tp, kvm_geterr_positive_test_error); | ATF_TP_ADD_TC(tp, kvm_geterr_positive_test_error); | ||||
ATF_TP_ADD_TC(tp, kvm_geterr_positive_test_no_error); | ATF_TP_ADD_TC(tp, kvm_geterr_positive_test_no_error); | ||||
#endif | #endif | ||||
return (atf_no_error()); | return (atf_no_error()); | ||||
} | } |
This doesn't follow style(9).