|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | +package com.cloud.cpu; |
| 18 | + |
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | +import static org.junit.Assert.assertThrows; |
| 21 | +import static org.junit.Assert.assertTrue; |
| 22 | + |
| 23 | +import org.junit.Test; |
| 24 | + |
| 25 | +public class CPUTest { |
| 26 | + @Test |
| 27 | + public void testCPUArchGetType() { |
| 28 | + assertEquals("i686", CPU.CPUArch.x86.getType()); |
| 29 | + assertEquals("x86_64", CPU.CPUArch.amd64.getType()); |
| 30 | + assertEquals("aarch64", CPU.CPUArch.arm64.getType()); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testCPUArchGetBits() { |
| 35 | + assertEquals(32, CPU.CPUArch.x86.getBits()); |
| 36 | + assertEquals(64, CPU.CPUArch.amd64.getBits()); |
| 37 | + assertEquals(64, CPU.CPUArch.arm64.getBits()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testCPUArchFromTypeWithValidValues() { |
| 42 | + assertEquals(CPU.CPUArch.x86, CPU.CPUArch.fromType("i686")); |
| 43 | + assertEquals(CPU.CPUArch.amd64, CPU.CPUArch.fromType("x86_64")); |
| 44 | + assertEquals(CPU.CPUArch.arm64, CPU.CPUArch.fromType("aarch64")); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testCPUArchFromTypeWithDefaultForBlankOrNull() { |
| 49 | + assertEquals(CPU.CPUArch.amd64, CPU.CPUArch.fromType("")); |
| 50 | + assertEquals(CPU.CPUArch.amd64, CPU.CPUArch.fromType(" ")); |
| 51 | + assertEquals(CPU.CPUArch.amd64, CPU.CPUArch.fromType(null)); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testCPUArchFromTypeWithInvalidValue() { |
| 56 | + Exception exception = assertThrows(IllegalArgumentException.class, () -> { |
| 57 | + CPU.CPUArch.fromType("unsupported"); |
| 58 | + }); |
| 59 | + assertTrue(exception.getMessage().contains("Unsupported arch type: unsupported")); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testCPUArchGetTypesAsCSV() { |
| 64 | + String expectedCSV = "i686,x86_64,aarch64"; |
| 65 | + assertEquals(expectedCSV, CPU.CPUArch.getTypesAsCSV()); |
| 66 | + } |
| 67 | +} |
0 commit comments