github.com/google/cadvisor@v0.49.1/perf/config_test.go (about) 1 // Copyright 2020 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package perf 16 17 import ( 18 "os" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 ) 23 24 func TestConfigParsing(t *testing.T) { 25 file, err := os.Open("testing/perf.json") 26 assert.Nil(t, err) 27 defer file.Close() 28 29 events, err := parseConfig(file) 30 31 assert.Nil(t, err) 32 assert.Len(t, events.Core.Events, 2) 33 assert.Len(t, events.Core.Events[0].events, 2) 34 assert.Equal(t, true, events.Core.Events[0].array) 35 assert.Equal(t, Event("instructions"), events.Core.Events[0].events[0]) 36 assert.Equal(t, Event("instructions_retired"), events.Core.Events[0].events[1]) 37 assert.Len(t, events.Core.Events[1].events, 1) 38 assert.Equal(t, false, events.Core.Events[1].array) 39 assert.Equal(t, Event("cycles"), events.Core.Events[1].events[0]) 40 41 assert.Len(t, events.Uncore.Events, 3) 42 assert.Equal(t, Event("cas_count_write"), events.Uncore.Events[0].events[0]) 43 assert.Equal(t, Event("uncore_imc_0/UNC_M_CAS_COUNT:RD"), events.Uncore.Events[1].events[0]) 44 assert.Equal(t, Event("uncore_ubox/UNC_U_EVENT_MSG"), events.Uncore.Events[2].events[0]) 45 46 assert.Len(t, events.Uncore.CustomEvents, 1) 47 assert.Equal(t, Config{0x5300}, events.Uncore.CustomEvents[0].Config) 48 assert.Equal(t, uint32(0x12), events.Uncore.CustomEvents[0].Type) 49 assert.Equal(t, Event("cas_count_write"), events.Uncore.CustomEvents[0].Name) 50 51 }