#!/usr/bin/env python #-*- coding: utf-8 -*- # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. # # Use of this source code is governed by a BSD-style license # that can be found in the LICENSE file in the root of the source # tree. An additional intellectual property rights grant can be found # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. """Test the tgrid parser. Compatible with build bot 0.8.4 P1. """ import unittest import tgrid_parser SAMPLE_FILE = """ Buildbot
Home - Waterfall Grid T-Grid Console Builders Recent Builds Buildslaves Changesources - JSON API - About

Transposed Grid View

WebRTC Android AndroidNDK Chrome ChromeOS Linux32DBG Linux32Release Linux64DBG Linux64DBG-GCC4.6 Linux64Release LinuxClang LinuxValgrind LinuxVideoTest MacOS32DBG MacOS32Release
(building)
Win32Debug Win32Release
(building)
2006 OK OK warnings OK OK OK OK OK OK OK OK   OK   OK  
2007 OK OK OK OK OK OK OK OK OK OK OK failed
voe_auto_test
OK OK OK OK
2008 OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK
2010 OK OK   OK OK OK OK OK OK OK OK OK OK OK OK OK
2011 OK OK   OK OK OK OK OK OK OK OK OK OK building OK building
latest building OK
""" MINIMAL_OK = """ 1570 OK """ MINIMAL_FAIL = """ 1573 failed
voe_auto_test
""" MINIMAL_BUILDING = """ 1576 building voe_auto_test """ MINIMAL_WARNED = """ 1576 warnings
make chrome """ MINIMAL_EXCEPTION = """ 1576 exception
Sync """ MINIMAL_EXCEPTION_SLAVE_LOST = """ 1576 build
successful
exception
slave
lost
""" MINIMAL_IN_TRUNK_SOURCESTAMP = """ 1576 in trunk build
successful
exception
slave
lost
""" class TGridParserTest(unittest.TestCase): def test_parser_throws_exception_on_empty_html(self): self.assertRaises(tgrid_parser.FailedToParseBuildStatus, tgrid_parser.parse_tgrid_page, '') def test_parser_finds_successful_bot(self): result = tgrid_parser.parse_tgrid_page(MINIMAL_OK) self.assertEqual(1, len(result), 'There is only one bot in the sample.') first_mapping = result.items()[0] # Note: the parser should unescape % quotations, like %20 for space. self.assertEqual('1570--Linux Clang [stable]', first_mapping[0]) self.assertEqual('121--OK', first_mapping[1]) def test_parser_finds_failed_bot(self): result = tgrid_parser.parse_tgrid_page(MINIMAL_FAIL) self.assertEqual(1, len(result), 'There is only one bot in the sample.') first_mapping = result.items()[0] self.assertEqual('1573--Linux Large Tests', first_mapping[0]) self.assertEqual('731--failed', first_mapping[1]) def test_parser_finds_building_bot(self): result = tgrid_parser.parse_tgrid_page(MINIMAL_BUILDING) self.assertEqual(1, len(result), 'There is only one bot in the sample.') first_mapping = result.items()[0] self.assertEqual('1576--Win32Debug', first_mapping[0]) self.assertEqual('434--building', first_mapping[1]) def test_parser_finds_warnings(self): result = tgrid_parser.parse_tgrid_page(MINIMAL_WARNED) self.assertEqual(1, len(result), 'There is only one bot in the sample.') first_mapping = result.items()[0] self.assertEqual('1576--Chrome', first_mapping[0]) self.assertEqual('109--warnings', first_mapping[1]) def test_parser_finds_exception_and_maps_to_failed(self): result = tgrid_parser.parse_tgrid_page(MINIMAL_EXCEPTION) self.assertEqual(1, len(result), 'There is only one bot in the sample.') first_mapping = result.items()[0] self.assertEqual('1576--Chrome', first_mapping[0]) self.assertEqual('109--failed', first_mapping[1]) def test_parser_finds_exception_slave_lost_and_maps_to_failed(self): # This is to work around a bug in build bot 0.8.4p1 where it may say that # the build was successful AND the slave was lost. In this case the build # is not actually successful, so treat it as such. result = tgrid_parser.parse_tgrid_page(MINIMAL_EXCEPTION_SLAVE_LOST) self.assertEqual(1, len(result), 'There is only one bot in the sample.') first_mapping = result.items()[0] self.assertEqual('1576--LinuxValgrind', first_mapping[0]) self.assertEqual('324--failed', first_mapping[1]) def test_parser_finds_all_bots_and_revisions_except_forced_builds(self): result = tgrid_parser.parse_tgrid_page(SAMPLE_FILE) # 5*16 = 80 bots in sample. There's also five empty results because some # bots did not run for some revisions, so 80 - 5 = 75 results. There are # two additional statuses under an explicit 'latest' revision, which should # be ignored since that means the build was forced. self.assertEqual(75, len(result)) # Make some samples self.assertTrue(result.has_key('2006--ChromeOS')) self.assertEquals('933--OK', result['2006--ChromeOS']) self.assertTrue(result.has_key('2006--Chrome')) self.assertEquals('243--warnings', result['2006--Chrome']) self.assertTrue(result.has_key('2006--LinuxClang')) self.assertEquals('610--OK', result['2006--LinuxClang']) # This one happened to not get reported in revision 2006, but it should be # there in the next revision: self.assertFalse(result.has_key('2006--Win32Release')) self.assertTrue(result.has_key('2007--Win32Release')) self.assertEquals('809--OK', result['2007--Win32Release']) self.assertTrue(result.has_key('2007--ChromeOS')) self.assertEquals('934--OK', result['2007--ChromeOS']) self.assertTrue(result.has_key('2007--LinuxVideoTest')) self.assertEquals('731--failed', result['2007--LinuxVideoTest']) self.assertTrue(result.has_key('2011--Win32Release')) self.assertEquals('813--building', result['2011--Win32Release']) if __name__ == '__main__': unittest.main()