1#!/usr/bin/env python 2# 3# Copyright (C) 2018 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# 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, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import unittest 18from extract_kernel import get_version, dump_version 19 20class ExtractKernelTest(unittest.TestCase): 21 def test_extract_version(self): 22 self.assertEqual("4.9.100", get_version( 23 b'Linux version 4.9.100-a123 (a@a) (a) a\n\x00', 0)) 24 self.assertEqual("4.9.123", get_version( 25 b'Linux version 4.9.123 (@) () \n\x00', 0)) 26 27 def test_dump_self(self): 28 self.assertEqual("4.9.1", dump_version( 29 b"trash\x00Linux version 4.8.8\x00trash\x00" 30 "other trash Linux version 4.9.1-g3 (2@s) (2) a\n\x00")) 31