private void addInstrumentation(){ int index = LoopCounter.getInstance().getNewIndex(); mv.visitMethodInsn(Opcodes.INVOKESTATIC,LOOP_COUNTER, "getInstance", "()L"+LOOP_COUNTER+";" , false); mv.visitLdcInsn(index); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, LOOP_COUNTER, "checkLoop", "(I)V", false); } }
@Test(timeout = 10000) public void testInfiniteLoop() { Assert.assertTrue(RuntimeSettings.maxNumberOfIterationsPerLoop > 0);//should be on by default int first = LoopCounter.getInstance().getNewIndex(); int second = LoopCounter.getInstance().getNewIndex(); while (true) { LoopCounter.getInstance().checkLoop(first); for (int i = 0; i < 100; i++) { try { LoopCounter.getInstance().checkLoop(second); //this should fail first } catch (TooManyResourcesException e) { //expected return; } } } }